Ejemplo n.º 1
0
def test_get_symmetry_hash():
    """Test the symmetry hashes"""
    zif3 = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "ZIF-3.cif"))
    print(type(zif3.structure))
    hash_a = get_symmetry_hash(zif3.structure, tight=True)
    assert len(hash_a) == 275
    hash_b = get_symmetry_hash(zif3.structure)
    assert len(hash_b) == 47
    assert hash_a[-3:] == hash_b[-3:]

    zif4 = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "ZIF-4.cif"))
    hash_zif4_a = get_symmetry_hash(zif4.structure, tight=True)
    hash_zif4_b = get_symmetry_hash(zif4.structure)

    assert hash_zif4_a != hash_a
    assert hash_zif4_b != hash_b

    assert zif4.symmetry_hash == hash_zif4_b

    structure = Structure.from_file(
        os.path.join(THIS_DIR, "test_files", "ABAXUZ.cif"))
    original_hash = get_symmetry_hash(MOFChecker(structure).structure)

    # rotate structure
    rotation_transformer = RotationTransformation([1, 0, 0], 10)
    rotated_structure = rotation_transformer.apply_transformation(structure)
    assert get_symmetry_hash(
        MOFChecker(rotated_structure).structure) == original_hash

    # create supercell
    structure.make_supercell([1, 2, 1])
    print(type(structure))
    assert get_symmetry_hash(MOFChecker(structure).structure) == original_hash
Ejemplo n.º 2
0
def test_undercoordinated_n():
    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "VUGYED_clean.cif"))
    )
    assert mofchecker.has_undercoordinated_n == False

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "mil-53-al-nh2.cif"))
    )
    assert mofchecker.has_undercoordinated_n == True

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "ABAXUZ.cif"))
    )
    assert mofchecker.has_undercoordinated_n == False

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "1246903.cif"))
    )
    assert mofchecker.has_undercoordinated_n == False

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "1246903_missing_H.cif")
        )
    )
    assert mofchecker.has_undercoordinated_n == True
Ejemplo n.º 3
0
def test_has_oms(get_cn4_structure, get_cn5_paddlewheel_structure):
    """Test two specific structures"""
    omsdetector = MOFChecker(get_cn4_structure)
    assert omsdetector.has_oms

    omsdetector = MOFChecker(get_cn5_paddlewheel_structure)
    assert not omsdetector.has_oms
Ejemplo n.º 4
0
def test_has_oms(get_cn4_structre, get_cn5_paddlewheel_structure):

    omsdetector = MOFChecker(get_cn4_structre)
    assert omsdetector.has_oms == True

    omsdetector = MOFChecker(get_cn5_paddlewheel_structure)
    assert omsdetector.has_oms == False
Ejemplo n.º 5
0
def test_overvalent_h():
    mofchecker = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "overvalent_h.cif"))
    assert mofchecker.has_overvalent_h
    assert len(mofchecker.overvalent_h_indices) == 3

    mofchecker = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "XIGFOJ_manual.cif"))
    assert not mofchecker.has_overvalent_h
Ejemplo n.º 6
0
def test_lone_atom():
    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "ABAVIJ_clean.cif"))
    )
    assert mofchecker.has_lone_atom == False

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "HKUST_floating.cif"))
    )
    assert mofchecker.has_lone_atom == True
Ejemplo n.º 7
0
def test_undercoordinated_c():
    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "ABAVIJ_clean.cif"))
    )
    assert mofchecker.has_undercoordinated_c == False

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files", "AHOKIR_clean.cif"))
    )
    assert mofchecker.has_undercoordinated_c == True
Ejemplo n.º 8
0
def test_overvalent_c(get_overvalent_c_structures):
    for structure in get_overvalent_c_structures:
        mofchecker = MOFChecker(structure)
        assert mofchecker.has_overvalent_c == True

    mofchecker = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "XIGFOJ_manual.cif"))
    assert mofchecker.has_overvalent_c == False

    # alkine ligand
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "RUDQUD_clean.cif")))
    assert mofchecker.has_overvalent_c == False
Ejemplo n.º 9
0
def test_lone_molecule_past_issue():
    atoms = read(os.path.join(THIS_DIR, "test_files", "floating_check.cif"))
    mofchecker = MOFChecker.from_ase(atoms)
    assert len(mofchecker.lone_molecule_indices) == 1
    assert len(mofchecker.lone_molecule_indices[0]) == 5
    species = []
    for ind in mofchecker.lone_molecule_indices[0]:
        species.append(str(mofchecker.structure[ind].specie))
    assert set(species) == set(["H", "H", "H", "H", "C"])
    assert mofchecker.has_lone_molecule == True

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "OTOXIF_clean.cif")))
    assert mofchecker.has_lone_molecule == False
Ejemplo n.º 10
0
def test_undercoordinated_n_past_issue():
    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "axipee.cif")))
    assert mofchecker.has_undercoordinated_n == False

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "ABOVOF_FSR.cif")))
    assert mofchecker.has_undercoordinated_n == False

    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "abiqae.cif")))
    assert mofchecker.has_undercoordinated_n == False
Ejemplo n.º 11
0
def test_graph_hash_false_negatives():
    """Test the hash on past issues of false negatives.

    Cases of structures that should match but the graph hash did not.
    """
    # issue 107: Mn-MOF-74: ASR ORIWET and COKNUN… give different hash
    oriwet = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "ORIWET.cif")))

    coknun = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "COKNUN.cif")))

    assert oriwet.graph_hash == coknun.graph_hash
    assert oriwet.scaffold_hash == coknun.scaffold_hash
Ejemplo n.º 12
0
def test_lone_molecule():
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "ABAVIJ_clean.cif")))
    assert mofchecker.has_lone_molecule == False

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "HKUST_floating.cif")))
    assert mofchecker.has_lone_molecule == True

    assert mofchecker.lone_molecule_indices == [[144]]

    atoms = read(os.path.join(THIS_DIR, "test_files", "overvalent_h.cif"))
    mofchecker = MOFChecker.from_ase(atoms, primitive=False)
    assert len(mofchecker.lone_molecule_indices) == 3
Ejemplo n.º 13
0
def test_undercoordinated_c():
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "ABAVIJ_clean.cif")))
    assert mofchecker.has_undercoordinated_c == False

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "AHOKIR_clean.cif")))
    assert mofchecker.has_undercoordinated_c == True

    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "missing_h_on_c.cif")))
    assert mofchecker.has_undercoordinated_c == True
    assert len(mofchecker.undercoordinated_c_indices) == 2
    assert len(mofchecker.undercoordinated_c_candidate_positions) == 2
Ejemplo n.º 14
0
def get_feat_one_structure(cif):
    """Run the MOFCheck on one structure"""
    try:
        mofchecker = MOFChecker.from_cif(cif)
        descriptors = mofchecker.get_mof_descriptors()
        return descriptors
    except NoMetal:
        print("{} has no metal".format(cif))
        return None
Ejemplo n.º 15
0
def test_graph_hash_false_positives():
    """Test the hash on past issues of false positives.

    Cases where different structures gave the same hash.
    """
    # issue 130
    cof_18141N2 = MOFChecker.from_cif(  # pylint: disable=invalid-name
        os.path.join(THIS_DIR, "test_files", "18141N2.cif"))
    cof_20211N2 = MOFChecker.from_cif(  # pylint: disable=invalid-name
        os.path.join(THIS_DIR, "test_files", "20211N2.cif"))
    assert cof_18141N2.graph_hash != cof_20211N2.graph_hash

    # # Daniele's report
    mmpf7 = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "943643.cif")))
    mmpf8 = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "943644.cif")))

    assert mmpf7.graph_hash != mmpf8.graph_hash
    assert mmpf7.scaffold_hash != mmpf8.scaffold_hash
Ejemplo n.º 16
0
def test_unknown_elements():
    """Parsing structure with unknown element raises warning for covalent radius."""
    # with pytest.warns(UserWarning) as record:
    #     mofchecker = MOFCheƒ√cker.from_cif(
    #         os.path.join(THIS_DIR, "test_files", "GUPQOA.cif")
    #     )
    #     mofchecker.get_mof_descriptors()
    # assert len(record) >= 1

    with pytest.raises(NotImplementedError):
        mofchecker = MOFChecker.from_cif(
            os.path.join(THIS_DIR, "test_files", "GUPQOA.cif"))
        mofchecker.get_mof_descriptors()
Ejemplo n.º 17
0
 def check_structure(self, _=None):
     if self.structure is None:
         self.text.value = ""
     else:
         self.text.value = ""
         self.mfchk = MOFChecker.from_ase(self.structure, primitive=False)
         issue_found = False
         for (check_name, check) in self.mfchk.checks.items():
             if check_name in ENABLED_CHECKS:
                 if not check.is_ok:
                     issue_found = True
                 self.text.value += "\u2705 OK: " if check.is_ok else "\u274C Fail: "
                 self.text.value += f"{check.description} </br>"
         self.check_button.button_style = "danger" if issue_found else "success"
Ejemplo n.º 18
0
def run(primitive, descriptors, cif_files):
    """
    Check provided structures and print list of JSON objects with descriptors.
    """
    # Note: we want to see output as things progress,
    # thus this clumsy way of creating a JSON list
    print("[")
    for index, structure_file in enumerate(cif_files):
        mofchecker = MOFChecker.from_cif(structure_file, primitive=primitive)
        descriptors = mofchecker.get_mof_descriptors(descriptors=descriptors)

        string = json.dumps(descriptors, indent=2)
        if index != len(cif_files) - 1:
            string += ","
        print(string)
    print("]")
Ejemplo n.º 19
0
    def check_structure(self, _=None):

        if self.structure is None:
            return

        self.mfchk = MOFChecker.from_ase(self.structure, primitive=False)
        self.checks = []
        if self.structure:
            self.checks = [
                check for (check_name, check) in self.mfchk.checks.items()
                if check_name in ENABLED_CHECKS
            ]

        issue_found = False

        with self._output:
            clear_output()
            for check in self.checks:
                if not check.is_ok:
                    issue_found = True
                    try:
                        selection = list(
                            chain.from_iterable(check.flagged_indices))
                    except TypeError:
                        selection = check.flagged_indices
                    button = ipw.Button(description="Select",
                                        layout={"width": "initial"})
                    button.on_click(
                        fct.partial(self._select_atoms, selection=selection))
                    text = ipw.HTML("Found " + check.name.lower())
                    display(ipw.HBox([text, button]))

            if (self.mfchk.undercoordinated_c_candidate_positions +
                    self.mfchk.undercoordinated_n_candidate_positions):
                self.missing_h_button.disabled = False
                self.missing_h_button.on_click(self.add_missing_hydrogens)
                display(
                    ipw.HBox([
                        ipw.HTML("Missing hydrogens found"),
                        self.missing_h_button
                    ]))

            if not issue_found:
                display(ipw.HTML("No issues found \u2705"))
Ejemplo n.º 20
0
def test_overvalent_c_past_issue():
    # based on issue https://github.com/kjappelbaum/mofchecker/issues/63
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "AGARUW_clean.cif")))
    assert mofchecker.has_overvalent_c == False
Ejemplo n.º 21
0
def _run_check(structure):
    mofcheckerinstance = MOFChecker(structure)
    result = mofcheckerinstance.get_mof_descriptors()

    return mofcheckerinstance, result
Ejemplo n.º 22
0
def test_overlaps():
    mofchecker = MOFChecker.from_cif(
        os.path.join(THIS_DIR, "test_files", "overvalent_h.cif"))
    assert not mofchecker.has_atomic_overlaps
Ejemplo n.º 23
0
def test_is_porous(get_cn5_paddlewheel_structure):
    mc = MOFChecker(get_cn5_paddlewheel_structure)
    assert mc.is_porous == True
Ejemplo n.º 24
0
def test_name():
    s = os.path.join(THIS_DIR, "test_files", "ABAVIJ_clean.cif")
    mofchecker = MOFChecker.from_cif(s)
    assert mofchecker.name == "ABAVIJ_clean"
Ejemplo n.º 25
0
def test_chargecheck():
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "AMUFIZ_clean.cif")))
    assert mofchecker.has_high_charges == False
Ejemplo n.º 26
0
def test_has_oms_multiple(get_testdict):
    """Test on a bunch of different structures"""
    for key, value in get_testdict.items():
        omsdetector = MOFChecker.from_cif(key)
        assert omsdetector.has_oms == value
Ejemplo n.º 27
0
def test_partial_occupancy():
    with pytest.raises(NotImplementedError):
        MOFChecker.from_cif(os.path.join(THIS_DIR, "test_files", "ABUBIK.cif"))
Ejemplo n.º 28
0
def slow_check_undercoordinated_c_past_issue():
    mofchecker = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "DALVIY_clean.cif")))
    assert mofchecker.has_undercoordinated_c == False
Ejemplo n.º 29
0
def test_graph_hash_robustness():  # pylint: disable=too-many-locals
    """Check that duplicating or rotating the structure produces the same hash."""
    structure = Structure.from_file(
        os.path.join(THIS_DIR, "test_files", "ABAXUZ.cif"))
    original_hash = MOFChecker(structure).graph_hash

    # rotate structure
    rotation_transformer = RotationTransformation([1, 0, 0], 10)
    rotated_structure = rotation_transformer.apply_transformation(structure)
    assert MOFChecker(rotated_structure).graph_hash == original_hash

    # create supercell
    structure.make_supercell([1, 2, 1])
    assert MOFChecker(structure).graph_hash == original_hash

    # check the MOF-74 structures
    mohgoi_checker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "MOHGOI.cif")))

    todyuj_checker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "TODYUJ.cif")))

    vogtiv_checker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "VOGTIV.cif")))

    # There water on TODYUJ
    assert mohgoi_checker.graph_hash != todyuj_checker.graph_hash
    # one is the supercell of the other
    assert mohgoi_checker.graph_hash == vogtiv_checker.graph_hash

    # MOF-74-Zr.cif
    mof_74_zr = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "MOF-74-Zr.cif")))
    assert mof_74_zr.graph_hash != todyuj_checker.graph_hash
    assert mof_74_zr.graph_hash != vogtiv_checker.graph_hash

    # # MOF-74-Zn.cif
    mof_74_zn = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "MOF-74-Zn.cif")))
    assert mof_74_zr.scaffold_hash == mof_74_zn.scaffold_hash
    assert mof_74_zr.graph_hash != mof_74_zn.graph_hash

    # # MOF-5 is not ZIF-8
    mof_5 = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "mof-5_cellopt.cif")))
    zif_8 = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "ZIF-8-RASPA.cif")))
    assert mof_5.graph_hash != zif_8.graph_hash

    # # Mn-MOF-74 and UiO-67
    coknun = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "coknun01.cif")))
    wizmac = MOFChecker(
        Structure.from_file(
            os.path.join(THIS_DIR, "test_files", "WIZMAV02_auto.cif")))
    assert coknun.graph_hash != wizmac.graph_hash
Ejemplo n.º 30
0
def test_graph_hash():
    """Basic check that the function call works"""
    mofchecker = MOFChecker(
        Structure.from_file(os.path.join(THIS_DIR, "test_files",
                                         "ABAXUZ.cif")))
    assert isinstance(mofchecker.graph_hash, str)