Ejemplo n.º 1
0
    def test_all_nn_classes(self):
        self.assertEqual(MinimumDistanceNN(cutoff=5, get_all_sites=True).get_cn(
            self.cscl, 0), 14)
        self.assertEqual(MinimumDistanceNN().get_cn(self.diamond, 0), 4)
        self.assertEqual(MinimumDistanceNN().get_cn(self.nacl, 0), 6)
        self.assertEqual(MinimumDistanceNN().get_cn(self.lifepo4, 0), 6)
        self.assertEqual(MinimumDistanceNN(tol=0.01).get_cn(self.cscl, 0), 8)
        self.assertEqual(MinimumDistanceNN(tol=0.1).get_cn(self.mos2, 0), 6)

        for image in MinimumDistanceNN(tol=0.1).get_nn_images(self.mos2, 0):
            self.assertTrue(image in [(0, 0, 0), (0, 1, 0), (-1, 0, 0),
                                      (0, 0, 0), (0, 1, 0), (-1, 0, 0)])

        okeeffe = MinimumOKeeffeNN(tol=0.01)
        self.assertEqual(okeeffe.get_cn(self.diamond, 0), 4)
        self.assertEqual(okeeffe.get_cn(self.nacl, 0), 6)
        self.assertEqual(okeeffe.get_cn(self.cscl, 0), 8)
        self.assertEqual(okeeffe.get_cn(self.lifepo4, 0), 2)

        virenn = MinimumVIRENN(tol=0.01)
        self.assertEqual(virenn.get_cn(self.diamond, 0), 4)
        self.assertEqual(virenn.get_cn(self.nacl, 0), 6)
        self.assertEqual(virenn.get_cn(self.cscl, 0), 8)
        self.assertEqual(virenn.get_cn(self.lifepo4, 0), 2)

        brunner_recip = BrunnerNN_reciprocal(tol=0.01)
        self.assertEqual(brunner_recip.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_recip.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_recip.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_recip.get_cn(self.lifepo4, 0), 6)

        brunner_rel = BrunnerNN_relative(tol=0.01)
        self.assertEqual(brunner_rel.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_rel.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_rel.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_rel.get_cn(self.lifepo4, 0), 6)

        brunner_real = BrunnerNN_real(tol=0.01)
        self.assertEqual(brunner_real.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_real.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_real.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_real.get_cn(self.lifepo4, 0), 30)

        econn = EconNN()
        self.assertEqual(econn.get_cn(self.diamond, 0), 4)
        self.assertEqual(econn.get_cn(self.nacl, 0), 6)
        self.assertEqual(econn.get_cn(self.cscl, 0), 14)
        self.assertEqual(econn.get_cn(self.lifepo4, 0), 6)

        voroinn = VoronoiNN(tol=0.5)
        self.assertEqual(voroinn.get_cn(self.diamond, 0), 4)
        self.assertEqual(voroinn.get_cn(self.nacl, 0), 6)
        self.assertEqual(voroinn.get_cn(self.cscl, 0), 8)
        self.assertEqual(voroinn.get_cn(self.lifepo4, 0), 6)

        crystalnn = CrystalNN()
        self.assertEqual(crystalnn.get_cn(self.diamond, 0), 4)
        self.assertEqual(crystalnn.get_cn(self.nacl, 0), 6)
        self.assertEqual(crystalnn.get_cn(self.cscl, 0), 8)
        self.assertEqual(crystalnn.get_cn(self.lifepo4, 0), 6)
Ejemplo n.º 2
0
    def test_all_nn_classes(self):
        self.assertAlmostEqual(MinimumDistanceNN().get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(MinimumDistanceNN().get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(
            MinimumDistanceNN(tol=0.01).get_cn(self.cscl, 0), 8)
        self.assertAlmostEqual(
            MinimumDistanceNN(tol=0.1).get_cn(self.mos2, 0), 6)
        for image in MinimumDistanceNN(tol=0.1).get_nn_images(self.mos2, 0):
            self.assertTrue(image in [(0, 0, 0), (0, 1,
                                                  0), (-1, 0,
                                                       0), (0, 0,
                                                            0), (0, 1,
                                                                 0), (-1, 0,
                                                                      0)])

        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(
            MinimumVIRENN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(MinimumVIRENN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(MinimumVIRENN(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(
            BrunnerNN_reciprocal(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(
            BrunnerNN_reciprocal(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(
            BrunnerNN_reciprocal(tol=0.01).get_cn(self.cscl, 0), 14)

        self.assertAlmostEqual(
            BrunnerNN_relative(tol=0.01).get_cn(self.diamond, 0), 16)
        self.assertAlmostEqual(
            BrunnerNN_relative(tol=0.01).get_cn(self.nacl, 0), 18)
        self.assertAlmostEqual(
            BrunnerNN_relative(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(
            BrunnerNN_real(tol=0.01).get_cn(self.diamond, 0), 16)
        self.assertAlmostEqual(
            BrunnerNN_real(tol=0.01).get_cn(self.nacl, 0), 18)
        self.assertAlmostEqual(
            BrunnerNN_real(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.cscl, 0), 14)

        self.assertAlmostEqual(VoronoiNN(tol=0.5).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(VoronoiNN(tol=0.5).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(VoronoiNN(tol=0.5).get_cn(self.cscl, 0), 8)
Ejemplo n.º 3
0
    def test_all_nn_classes(self):
        self.assertAlmostEqual(MinimumDistanceNN().get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(MinimumDistanceNN().get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(
            MinimumDistanceNN(tol=0.01).get_cn(self.cscl, 0), 8)
        self.assertAlmostEqual(
            MinimumDistanceNN(tol=0.1).get_cn(self.mos2, 0), 6)
        for image in MinimumDistanceNN(tol=0.1).get_nn_images(self.mos2, 0):
            self.assertTrue(image in [[0, 0, 0], [0, 1, 0], [-1, 0, 0], \
                    [0, 0, 0], [0, 1, 0], [-1, 0, 0]])

        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(
            MinimumOKeeffeNN(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(
            MinimumVIRENN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(MinimumVIRENN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(MinimumVIRENN(tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(BrunnerNN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(BrunnerNN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(BrunnerNN(tol=0.01).get_cn(self.cscl, 0), 14)

        self.assertAlmostEqual(
            BrunnerNN(mode="real", tol=0.01).get_cn(self.diamond, 0), 16)
        self.assertAlmostEqual(
            BrunnerNN(mode="real", tol=0.01).get_cn(self.nacl, 0), 18)
        self.assertAlmostEqual(
            BrunnerNN(mode="real", tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(
            BrunnerNN(mode="relative", tol=0.01).get_cn(self.diamond, 0), 16)
        self.assertAlmostEqual(
            BrunnerNN(mode="relative", tol=0.01).get_cn(self.nacl, 0), 18)
        self.assertAlmostEqual(
            BrunnerNN(mode="relative", tol=0.01).get_cn(self.cscl, 0), 8)

        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(EconNN(tol=0.01).get_cn(self.cscl, 0), 14)

        self.assertAlmostEqual(VoronoiNN_modified().get_cn(self.diamond, 0), 4)
        self.assertAlmostEqual(VoronoiNN_modified().get_cn(self.nacl, 0), 6)
        self.assertAlmostEqual(VoronoiNN_modified().get_cn(self.cscl, 0), 8)
Ejemplo n.º 4
0
def fragment_to_molgraph(fragment: Fragment) -> MoleculeGraph:
    """
    [summary]

    Parameters
    ----------
    fragment : Fragment
        [description]

    Returns
    -------
    pymatgen.analysis.graphs.MoleculeGraph
        [description]
    """
    mol = fragment.atoms.copy()
    dummies_idx = fragment.atoms.indices_from_symbol("X")
    mol.replace_species({"X": "H"})
    # setting up UFF type analysis
    uff_lib, uff_symbs = load_uff_lib(mol)
    # obtaining cutoffs from the maximum UFF radius
    strategy = EconNN(tol=0.3, use_fictive_radius=True, cutoff=10.0)
    mg = MoleculeGraph.with_local_env_strategy(mol, strategy=strategy)
    # add mmtypes
    mmtypes = find_mmtypes(molgraph=mg, uff_lib=uff_lib, uff_symbs=uff_symbs)
    for i, mmtype in enumerate(mmtypes):
        mg.molecule[i].properties["ufftype"] = mmtype
    # transfer tags from dummies
    if "tags" in mg.molecule.site_properties:
        for dummy_idx in dummies_idx:
            tag = mg.molecule[dummy_idx].properties["tags"]
            for site in mg.get_connected_sites(dummy_idx):
                mg.molecule[site.index].properties["tags"] = tag
    # remove dummies
    mg.remove_nodes(list(dummies_idx))
    return mg
Ejemplo n.º 5
0
def get_local_env_method(method):  # pylint:disable=too-many-return-statements
    """get a local environment method based on its name"""
    method = method.lower()

    if method.lower() == "crystalnn":
        # see eq. 15 and 16 in
        # https://pubs.acs.org/doi/full/10.1021/acs.inorgchem.0c02996
        # for the x_diff_weight parameter.
        # in the paper it is called δen and it is set to 3
        # we found better results by lowering this weight
        return CrystalNN(porous_adjustment=True,
                         x_diff_weight=1.5,
                         search_cutoff=4.5)
    if method.lower() == "econnn":
        return EconNN()
    if method.lower() == "brunnernn":
        return BrunnerNN_relative()
    if method.lower() == "minimumdistance":
        return MinimumDistanceNN()
    if method.lower() == "vesta":
        return VESTA_NN
    if method.lower() == "voronoinn":
        return VoronoiNN()
    if method.lower() == "atr":
        return ATR_NN
    if method.lower() == "li":
        return LI_NN

    return JmolNN()
Ejemplo n.º 6
0
 def setUp(self):
     # set up a test structure, the coordinations are not correct and are only
     # for test purposes.
     structure = Structure.from_spacegroup(
         225,
         [[5.7, 0, 0], [0, 5.7, 0], [0, 0, 5.7]],
         ["Na1+", "Cl1-"],
         [[0, 0, 0], [0.5, 0, 0]],
     )
     all_sites_coordination = [{"Cl": 6}] * 4 + [{"Na": 8, "Cl": [6, 8]}] * 4
     structure.add_site_property("coordination", all_sites_coordination)
     self.structures = {"test_structure": structure}
     self.nn_methods = [MinimumVIRENN(), EconNN()]
Ejemplo n.º 7
0
def get_NNs_pm(atoms, site_idx, NN_method):
    """
	Get coordinating atoms to the adsorption site

	Args:
		atoms (Atoms object): atoms object of MOF

		site_idx (int): ASE index of adsorption site
		
		NN_method (string): string representing the desired Pymatgen
		nearest neighbor algorithm:
		refer to http://pymatgen.org/_modules/pymatgen/analysis/local_env.html
	
	Returns:
		neighbors_idx (list of ints): ASE indices of coordinating atoms
	"""
    #Convert ASE Atoms object to Pymatgen Structure object
    bridge = pm_ase.AseAtomsAdaptor()
    struct = bridge.get_structure(atoms)

    #Select Pymatgen NN algorithm
    NN_method = NN_method.lower()
    if NN_method == 'vire':
        nn_object = MinimumVIRENN()
    elif NN_method == 'voronoi':
        nn_object = VoronoiNN()
    elif NN_method == 'jmol':
        nn_object = JmolNN()
    elif NN_method == 'min_dist':
        nn_object = MinimumDistanceNN()
    elif NN_method == 'okeeffe':
        nn_object = MinimumOKeeffeNN()
    elif NN_method == 'brunner_real':
        nn_object = BrunnerNN_real()
    elif NN_method == 'brunner_recpirocal':
        nn_object = BrunnerNN_reciprocal()
    elif NN_method == 'brunner_relative':
        nn_object = BrunnerNN_relative()
    elif NN_method == 'econ':
        nn_object = EconNN()
    elif NN_method == 'dict':
        #requires a cutoff dictionary located in the pwd
        nn_object = CutOffDictNN(cut_off_dict='cut_off_dict.txt')
    elif NN_method == 'critic2':
        nn_object = Critic2NN()
    elif NN_method == 'openbabel':
        nn_object = OpenBabelNN()
    elif NN_method == 'covalent':
        nn_object = CovalentBondNN()
    elif NN_method == 'crystal':
        nn_object = CrystalNN(porous_adjustment=True)
    elif NN_method == 'crystal_nonporous':
        nn_object = CrystalNN(porous_adjustment=False)
    else:
        raise ValueError('Invalid NN algorithm specified')

    #Find coordinating atoms
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')
        neighbors = nn_object.get_nn_info(struct, site_idx)
    neighbors_idx = []
    for neighbor in neighbors:
        neighbors_idx.append(neighbor['site_index'])

    return neighbors_idx