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 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 test_from_local_env_and_equality_and_diff(self): nn = MinimumDistanceNN() sg = StructureGraph.with_local_env_strategy(self.structure, nn) self.assertEqual(sg.graph.number_of_edges(), 6) nn2 = MinimumOKeeffeNN() sg2 = StructureGraph.with_local_env_strategy(self.structure, nn2) self.assertTrue(sg == sg2) self.assertTrue(sg == self.mos2_sg) # TODO: find better test case where graphs are different diff = sg.diff(sg2) self.assertEqual(diff['dist'], 0)
def test_extract_molecules(self): structure_file = os.path.join(os.path.dirname(__file__), "..", "..", "..", 'test_files/C26H16BeN2O2S2.cif') s = Structure.from_file(structure_file) nn = MinimumOKeeffeNN() sg = StructureGraph.with_local_env_strategy(s, nn) molecules = sg.get_subgraphs_as_molecules() self.assertEqual(molecules[0].composition.formula, "Be1 H16 C26 S2 N2 O2") self.assertEqual(len(molecules), 1) molecules = self.mos2_sg.get_subgraphs_as_molecules() self.assertEqual(len(molecules), 0)
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