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 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