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)
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)
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)
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()]
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)
def get_neighbors_of_site_with_index_future(struct, n, approach="min_dist", \ delta=0.1, cutoff=10.0): """ Returns the neighbors of a given site using a specific neighbor-finding method. Args: struct (Structure): input structure. n (int): index of site in Structure object for which motif type is to be determined. approach (str): type of neighbor-finding approach, where "min_dist" will use the MinimumDistanceNN class, "voronoi" the VoronoiNN class, "min_OKeeffe" the MinimumOKeeffe class, and "min_VIRE" the MinimumVIRENN class. delta (float): tolerance involved in neighbor finding. cutoff (float): (large) radius to find tentative neighbors. Returns: neighbor sites. """ warnings.warn('This function will go into Pymatgen very soon.') if approach == "min_dist": return MinimumDistanceNN(tol=delta, cutoff=cutoff).get_nn( struct, n) elif approach == "voronoi": return VoronoiNN(tol=delta, cutoff=cutoff).get_nn( struct, n) elif approach == "min_OKeeffe": return MinimumOKeeffeNN(tol=delta, cutoff=cutoff).get_nn( struct, n) elif approach == "min_VIRE": return MinimumVIRENN(tol=delta, cutoff=cutoff).get_nn( struct, n) else: raise RuntimeError("unsupported neighbor-finding method ({}).".format( approach))
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