def test_generate_adsorption_structures(self): co = Molecule("CO", [[0, 0, 0], [0, 0, 1.23]]) structures = self.asf_111.generate_adsorption_structures( co, repeat=[2, 2, 1]) self.assertEqual(len(structures), 4) sites = self.asf_111.find_adsorption_sites() # Check repeat functionality self.assertEqual( len([ site for site in structures[0] if site.properties['surface_properties'] != 'adsorbate' ]), 4 * len(self.asf_111.slab)) for n, structure in enumerate(structures): self.assertArrayAlmostEqual(structure[-2].coords, sites['all'][n]) find_args = {"positions": ["hollow"]} structures_hollow = self.asf_111.\ generate_adsorption_structures(co, find_args=find_args) self.assertEqual(len(structures_hollow), len(sites['hollow'])) for n, structure in enumerate(structures_hollow): self.assertTrue( in_coord_list(sites['hollow'], structure[-2].coords)) # checks if top_surface boolean will properly # adsorb at the bottom surface when False o = Molecule("O", [[0, 0, 0]]) adslabs = self.asf_111_bottom.generate_adsorption_structures(o) for adslab in adslabs: sites = sorted(adslab, key=lambda site: site.frac_coords[2]) self.assertTrue(sites[0].species_string == "O")
def test_adsorb_both_surfaces(self): # Test out for monatomic adsorption o = Molecule("O", [[0, 0, 0]]) adslabs = self.asf_100.adsorb_both_surfaces(o) adslabs_one = self.asf_100.generate_adsorption_structures(o) self.assertEqual(len(adslabs), len(adslabs_one)) for adslab in adslabs: sg = SpacegroupAnalyzer(adslab) sites = sorted(adslab, key=lambda site: site.frac_coords[2]) self.assertTrue(sites[0].species_string == "O") self.assertTrue(sites[-1].species_string == "O") self.assertTrue(sg.is_laue()) # Test out for molecular adsorption oh = Molecule(["O", "H"], [[0, 0, 0], [0, 0, 1]]) adslabs = self.asf_100.adsorb_both_surfaces(oh) adslabs_one = self.asf_100.generate_adsorption_structures(oh) self.assertEqual(len(adslabs), len(adslabs_one)) for adslab in adslabs: sg = SpacegroupAnalyzer(adslab) sites = sorted(adslab, key=lambda site: site.frac_coords[2]) self.assertTrue(sites[0].species_string in ["O", "H"]) self.assertTrue(sites[-1].species_string in ["O", "H"]) self.assertTrue(sg.is_laue())
def test_from_bonding(self): # He: no bonding topologies helium = Molecule(["He"], [[0, 0, 0]]) topo_he = Topology.from_bonding(molecule=helium) self.assertIsNone(topo_he.topologies) # H2: 1 bond only hydrogen = Molecule(["H"] * 2, [[0, 0, 0], [0, 0, 0.7414]]) topo_h = Topology.from_bonding(molecule=hydrogen) tp_h = topo_h.topologies self.assertListEqual(tp_h["Bonds"], [[0, 1]]) self.assertNotIn("Angles", tp_h) self.assertNotIn("Dihedrals", tp_h) # water: 2 bonds and 1 angle only water = Molecule(["O", "H", "H"], [[0.0000, 0.0000, 0.1173], [0.0000, 0.7572, -0.4692], [0.0000, -0.7572, -0.4692]]) topo_water = Topology.from_bonding(molecule=water) tp_water = topo_water.topologies self.assertListEqual(tp_water["Bonds"], [[0, 1], [0, 2]]) self.assertListEqual(tp_water["Angles"], [[1, 0, 2]]) self.assertNotIn("Dihedrals", tp_water) # EtOH etoh = Molecule(["C", "C", "O", "H", "H", "H", "H", "H", "H"], [[1.1879, -0.3829, 0.0000], [0.0000, 0.5526, 0.0000], [-1.1867, -0.2472, 0.0000], [-1.9237, 0.3850, 0.0000], [2.0985, 0.2306, 0.0000], [1.1184, -1.0093, 0.8869], [1.1184, -1.0093, -0.8869], [-0.0227, 1.1812, 0.8852], [-0.0227, 1.1812, -0.8852]]) topo_etoh = Topology.from_bonding(molecule=etoh) tp_etoh = topo_etoh.topologies self.assertEqual(len(tp_etoh["Bonds"]), 8) etoh_bonds = [[0, 1], [0, 4], [0, 5], [0, 6], [1, 2], [1, 7], [1, 8], [2, 3]] np.testing.assert_array_equal(tp_etoh["Bonds"], etoh_bonds) self.assertEqual(len(tp_etoh["Angles"]), 13) etoh_angles = [[1, 0, 4], [1, 0, 5], [1, 0, 6], [4, 0, 5], [4, 0, 6], [5, 0, 6], [0, 1, 2], [0, 1, 7], [0, 1, 8], [2, 1, 7], [2, 1, 8], [7, 1, 8], [1, 2, 3]] np.testing.assert_array_equal(tp_etoh["Angles"], etoh_angles) self.assertEqual(len(tp_etoh["Dihedrals"]), 12) etoh_dihedrals = [[4, 0, 1, 2], [4, 0, 1, 7], [4, 0, 1, 8], [5, 0, 1, 2], [5, 0, 1, 7], [5, 0, 1, 8], [6, 0, 1, 2], [6, 0, 1, 7], [6, 0, 1, 8], [0, 1, 2, 3], [7, 1, 2, 3], [8, 1, 2, 3]] np.testing.assert_array_equal(tp_etoh["Dihedrals"], etoh_dihedrals) self.assertIsNotNone(json.dumps(topo_etoh.as_dict())) # bond flag to off topo_etoh0 = Topology.from_bonding(molecule=etoh, bond=False, angle=True, dihedral=True) self.assertIsNone(topo_etoh0.topologies) # angle or dihedral flag to off topo_etoh1 = Topology.from_bonding(molecule=etoh, angle=False) self.assertNotIn("Angles", topo_etoh1.topologies) topo_etoh2 = Topology.from_bonding(molecule=etoh, dihedral=False) self.assertNotIn("Dihedrals", topo_etoh2.topologies)
def test_init(self): mol = Molecule(["C", "H", "H", "H", "H"], self.coords) gau = GaussianInput(mol, charge=1, route_parameters={'SP': "", "SCF": "Tight"}) self.assertEqual(gau.spin_multiplicity, 2) mol = Molecule(["C", "H", "H", "H", "H"], self.coords, charge=-1) gau = GaussianInput(mol, route_parameters={'SP': "", "SCF": "Tight"}) self.assertEqual(gau.spin_multiplicity, 2) self.assertRaises(ValueError, GaussianInput, mol, spin_multiplicity=1)
def test_element_stats(self): test = ElementStats({ "H": [4, 2, 3], "O": [2, 3, 4] }, stats=["min", "max", "moment:1:10"]) self.assertEqual(test.transform(["H2O"]).shape, (1, 36)) res = test.transform(["H2O", "H2O"]) self.assertEqual(res.shape, (2, 36)) res2 = test.transform([Composition("H2O"), Composition("H2O")]) np.testing.assert_allclose(res.values, res2.values) dummy_h2o = Molecule(["H", "H", "O"], [[-0.5, 0, 0], [0.5, 0, 0], [0, 0, 0]]) res3 = test.transform([dummy_h2o, dummy_h2o]) np.testing.assert_allclose(res.values, res3.values) stats = ["min", "max", *["moment:%d:None" % i for i in range(1, 11)]] p0_names = ["p0_%s" % i for i in stats] p1_names = ["p1_%s" % i for i in stats] p2_names = ["p2_%s" % i for i in stats] all_names = [] for i, j, k in zip(p0_names, p1_names, p2_names): all_names.extend([i, j, k]) self.assertListEqual(list(res.columns), all_names)
def setUp(self): coords = [[0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], [1.026719, 0.000000, -0.363000], [-0.513360, -0.889165, -0.363000], [-0.513360, 0.889165, -0.363000]] self.mol = Molecule(["C", "H", "H", "H", "H"], coords)
def test__str__(self): species = ["C", "O"] coords = [ [-9.5782000000, 0.6241500000, 0.0000000000], [-7.5827400000, 0.5127000000, -0.0000000000], ] molecule = Molecule(species=species, coords=coords) rem = { "jobtype": "opt", "method": "wb97m-v", "basis": "def2-qzvppd", "max_scf_cycles": "300", "gen_scfman": "true", } str_test = QCInput(molecule=molecule, rem=rem).__str__().split("\n") str_actual_list = [ "$molecule", " 0 1", " C -9.5782000000 0.6241500000 0.0000000000", " O -7.5827400000 0.5127000000 -0.0000000000", "$end", "$rem", " job_type = opt", " method = wb97m-v", " basis = def2-qzvppd", " max_scf_cycles = 300", " gen_scfman = true", "$end", ] for i_str in str_actual_list: self.assertIn(i_str, str_test)
def setUp(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], [1.026719, 0.000000, -0.363000], [-0.513360, -0.889165, -0.363000], [-0.513360, 0.889165, -0.363000], ] self.coords = coords mol = Molecule(["C", "H", "H", "H", "H"], coords) self.cellin = FiestaInput( mol, correlation_grid={"dE_grid": u"0.500", "n_grid": u"14"}, Exc_DFT_option={"rdVxcpsi": u"1"}, COHSEX_options={ "eigMethod": u"C", "mix_cohsex": u"0.500", "nc_cohsex": u"0", "nit_cohsex": u"0", "nv_cohsex": u"0", "resMethod": u"V", "scf_cohsex_wf": u"0", }, GW_options={"nc_corr": u"10", "nit_gw": u"3", "nv_corr": u"10"}, BSE_TDDFT_options={ "do_bse": u"1", "do_tddft": u"0", "nc_bse": u"382", "nit_bse": u"50", "npsi_bse": u"1", "nv_bse": u"21", }, )
def test_simple_molecule_graph(self): mol = Molecule(["C", "H", "O"], [[0, 0, 0], [1, 0, 0], [2, 0, 0]]) graph = SimpleMolGraph().convert(mol) self.assertListEqual(to_list(graph["atom"]), [6, 1, 8]) self.assertTrue(np.allclose(graph["bond"], [1, 2, 1, 1, 2, 1])) self.assertListEqual(to_list(graph["index1"]), [0, 0, 1, 1, 2, 2]) self.assertListEqual(to_list(graph["index2"]), [1, 2, 0, 2, 0, 1])
def get_mol_object(self, id=0): """ make the pymatgen molecule object Args: id: the index of molecules in the given site Returns: a molecule object """ coord0 = self.mol.cart_coords.dot(self.orientation.matrix.T) # # Obtain the center in absolute coords if id <= len(self.wp.generators): op = self.wp.generators[id] center_relative = op.operate(self.position) center_relative -= np.floor(center_relative) #print(center_relative) center_absolute = np.dot(center_relative, self.lattice.matrix) # Rotate the molecule (Euclidean metric) op_m = self.wp.generators_m[id] rot = op_m.affine_matrix[0:3][:, 0:3].T tau = op_m.affine_matrix[0:3][:, 3] tmp = np.dot(coord0, rot) + tau # Add absolute center to molecule tmp += center_absolute return Molecule(self.symbols, tmp) else: raise ValueError("id is greater than the number of molecules")
def setUp(self): pymagen_sodium = Molecule(species=['Na'], coords=[[999.0, 999.0, 999.0]], charge=1) # noinspection PyProtectedMember sodium_obmol = BabelMolAdaptor(pymagen_sodium)._obmol acetoxyq_anion_qcout = QcOutput( os.path.join(test_dir, "acetoxyq_anion.out")) pymatgen_acetoxyq = acetoxyq_anion_qcout.data[0]["molecules"][-1] acetoxyq_obmol = BabelMolAdaptor(pymatgen_acetoxyq)._obmol tfsi_qcout = QcOutput(os.path.join(test_dir, "tfsi.qcout")) pymatgen_tfsi = tfsi_qcout.data[0]["molecules"][-1] # noinspection PyProtectedMember tfsi_obmol = BabelMolAdaptor(pymatgen_tfsi)._obmol fragments = [sodium_obmol, tfsi_obmol] nums_fragments = [1, 1] self.acetoxyq_natfsi_placer = IonPlacer(acetoxyq_obmol, fragments, nums_fragments, None) rad_util = AtomicRadiusUtils(covalent_radius_scale=3.0, metal_radius_scale=1.5) mol_radius = rad_util.get_radius(acetoxyq_obmol) cation_radius = rad_util.get_radius(sodium_obmol) anion_radius = rad_util.get_radius(tfsi_obmol) mol_coords = IonPlacer.normalize_molecule(acetoxyq_obmol) fragments_atom_radius = [cation_radius, anion_radius] nums_fragments = [1, 1] self.detector = ContactDetector(mol_coords, mol_radius, fragments_atom_radius, nums_fragments)
def make_a_mol_entry(): r""" Make a symmetric (fake) molecule with ring. O(0) / \ / \ H(1)--C(2)--C(3)--H(4) | | H(5) H(6) """ species = ["O", "H", "C", "C", "H", "H", "H"] coords = [ [0.0, 1.0, 0.0], [-1.5, 0.0, 0.0], [-0.5, 0.0, 0.0], [0.5, 0.0, 0.0], [1.5, 0.0, 0.0], [-0.5, -1.0, 0.0], [0.5, -1.0, 0.0], ] m = Molecule(species, coords) entry = MoleculeEntry(m, energy=0.0) return entry
def test__str__(self): species = ["C", "O"] coords = [[-9.5782000000, 0.6241500000, 0.0000000000], [-7.5827400000, 0.5127000000, -0.0000000000]] molecule = Molecule(species=species, coords=coords) rem = OrderedDict({ "jobtype": "opt", "method": "wB97M-V", "basis": "def2-QZVPPD", "max_scf_cycles": "300", "gen_scfman": "true" }) str_test = QCInput(molecule=molecule, rem=rem).__str__() str_actual = """$molecule 0 1 C -9.5782000000 0.6241500000 0.0000000000 O -7.5827400000 0.5127000000 -0.0000000000 $end $rem jobtype = opt method = wB97M-V basis = def2-QZVPPD max_scf_cycles = 300 gen_scfman = true $end """ self.assertEqual(str_actual, str_test)
def test_init(self): inner_charge = np.random.rand(10) - 0.5 outer_charge = np.random.rand(10) - 0.5 inner_velo = np.random.rand(10, 3) - 0.5 outer_velo = np.random.rand(10, 3) - 0.5 m = Molecule(["H"] * 10, np.random.rand(10, 3) * 100, site_properties={ "ff_map": ["D"] * 10, "charge": inner_charge, "velocities": inner_velo }) # q and v from site properties, while type from species_string topo = Topology(sites=m) self.assertListEqual(topo.type_by_sites, ["H"] * 10) np.testing.assert_array_equal(topo.charges, inner_charge) np.testing.assert_array_equal(topo.velocities, inner_velo) # q and v from overriding, while type from site property topo_override = Topology(sites=m, ff_label="ff_map", charges=outer_charge, velocities=outer_velo) self.assertListEqual(topo_override.type_by_sites, ["D"] * 10) np.testing.assert_array_equal(topo_override.charges, outer_charge) np.testing.assert_array_equal(topo_override.velocities, outer_velo) # test using a list of sites instead of SiteCollection topo_from_list = Topology(sites=m.sites) self.assertListEqual(topo_from_list.type_by_sites, topo.type_by_sites) np.testing.assert_array_equal(topo_from_list.charges, topo.charges) np.testing.assert_array_equal(topo_from_list.velocities, topo.velocities)
def setUpClass(cls): cls.structure = Structure.from_file( os.path.join(MODULE_DIR, "cifs", "BaTiO3_mp-2998_computed.cif")) cls.molecule = Molecule(["C", "O", "O"], [[0, 0, 0], [-1, 0, 0], [1, 0, 0]]) cls.mall = MinimumDistanceNNAll(4) cls.aapair = AllAtomPairs()
def parse_symmetry(pos): mol = Molecule(['C'] * len(pos), pos) try: symbol = PointGroupAnalyzer(mol, tolerance=0.1).sch_symbol except: symbol = 'N/A' return symbol
def test_element_stats(self): test = ElementStats({'H': [4, 2, 3], 'O': [2, 3, 4]}, stats=['min', 'max', 'moment:1:10']) self.assertEqual(test.transform(['H2O']).shape, (1, 36)) res = test.transform(['H2O', 'H2O']) self.assertEqual(res.shape, (2, 36)) res2 = test.transform([Composition('H2O'), Composition('H2O')]) np.testing.assert_allclose(res.values, res2.values) dummy_h2o = Molecule(['H', 'H', 'O'], [[-0.5, 0, 0], [0.5, 0, 0], [0, 0, 0]]) res3 = test.transform([dummy_h2o, dummy_h2o]) np.testing.assert_allclose(res.values, res3.values) stats = ['min', 'max', *['moment:%d:None' % i for i in range(1, 11)]] p0_names = ['p0_%s' % i for i in stats] p1_names = ['p1_%s' % i for i in stats] p2_names = ['p2_%s' % i for i in stats] all_names = [] for i, j, k in zip(p0_names, p1_names, p2_names): all_names.extend([i, j, k]) self.assertListEqual(list(res.columns), all_names)
def test_coulomb_matrix(self): # flat cm = CoulombMatrix(flatten=True) df = pd.DataFrame({"s": [self.diamond, self.nacl]}) with self.assertRaises(NotFittedError): df = cm.featurize_dataframe(df, "s") df = cm.fit_featurize_dataframe(df, "s") labels = cm.feature_labels() self.assertListEqual(labels, ["coulomb matrix eig 0", "coulomb matrix eig 1"]) self.assertArrayAlmostEqual(df[labels].iloc[0], [49.169453, 24.546758], decimal=5) self.assertArrayAlmostEqual(df[labels].iloc[1], [153.774731, 452.894322], decimal=5) # matrix species = ["C", "C", "H", "H"] coords = [[0, 0, 0], [0, 0, 1.203], [0, 0, -1.06], [0, 0, 2.263]] acetylene = Molecule(species, coords) morig = CoulombMatrix(flatten=False).featurize(acetylene) mtarget = [[36.858, 15.835391290, 2.995098235, 1.402827813], \ [15.835391290, 36.858, 1.4028278132103624, 2.9950982], \ [2.9368896127, 1.402827813, 0.5, 0.159279959], \ [1.4028278132, 2.995098235, 0.159279959, 0.5]] self.assertAlmostEqual(int(np.linalg.norm(morig - np.array(mtarget))), 0) m = CoulombMatrix(diag_elems=False, flatten=False).featurize(acetylene)[0] self.assertAlmostEqual(m[0][0], 0.0) self.assertAlmostEqual(m[1][1], 0.0) self.assertAlmostEqual(m[2][2], 0.0) self.assertAlmostEqual(m[3][3], 0.0)
def create_LiEC_pymatgen_mol(): """ O(3) -- Li(6) || C(1) / \ O(0) O(4) | | C(2) --- C(5) """ atoms = ["O", "C", "C", "O", "O", "C", "Li", "H", "H", "H", "H"] coords = [ [0.3103, -1.1776, -0.3722], [-0.6822, -0.5086, 0.3490], [1.5289, -0.4938, -0.0925], [-1.9018, -0.6327, -0.0141], [-0.2475, 0.9112, 0.3711], [1.1084, 0.9722, -0.0814], [-2.0519, 1.1814, -0.2310], [2.2514, -0.7288, -0.8736], [1.9228, -0.8043, 0.8819], [1.1406, 1.4103, -1.0835], [1.7022, 1.5801, 0.6038], ] charge = 0 m = Molecule(atoms, coords, charge) return m
def test_simple_molecule_graph(self): mol = Molecule(['C', 'H', 'O'], [[0, 0, 0], [1, 0, 0], [2, 0, 0]]) graph = SimpleMolGraph().convert(mol) self.assertListEqual(graph['atom'], [6, 1, 8]) self.assertTrue(np.allclose(graph['bond'], [1, 2, 1, 1, 2, 1])) self.assertListEqual(graph['index1'], [0, 0, 1, 1, 2, 2]) self.assertListEqual(graph['index2'], [1, 2, 0, 2, 0, 1])
def random_purturbation_index(): if is_pbc(): struct=readstructure(crystal=True,molecule=False) natom=len(struct) d=np.zeros(2,dtype=int) while d[0]==d[1]: d=np.random.randint(0,natom,2) coord=struct.frac_coords coord[[d[0], d[1]], :] = coord[[d[1], d[0]], :] tmp_struct=Structure(struct.lattice,struct.species,coord) fname='swap_'+str(d[0]+1)+'_'+str(d[1]+1)+'.vasp' proc_str="Saving data to "+ fname +" File ..." procs(proc_str,0,sp='-->>') tmp_struct.to(filename=fname,fmt='poscar') else: struct=readstructure(crystal=False,molecule=True) # print(struct) coord=struct.cart_coords natom=len(struct) d=np.zeros(2,dtype=int) while d[0]==d[1]: d=np.random.randint(0,natom,2) coord[[d[0], d[1]], :] = coord[[d[1], d[0]], :] tmp_struct=Molecule(struct.species,coord) fname='swap_'+str(d[0]+1)+'_'+str(d[1]+1)+'.xyz' proc_str="Saving data to "+ fname +" File ..." procs(proc_str,0,sp='-->>') tmp_struct.to(filename=fname,fmt='xyz') return
def test_adsorb_both_surfaces(self): o = Molecule("O", [[0, 0, 0]]) adslabs = adsorb_both_surfaces(self.slab_dict["111"], o) for adslab in adslabs: sites = sorted(adslab, key=lambda site: site.frac_coords[2]) self.assertTrue(sites[0].species_string == "O") self.assertTrue(sites[-1].species_string == "O") self.assertTrue(adslab.is_symmetric())
def outputMolecule(singleMol, dataDir): molecule = Molecule([], []) for site in singleMol: molecule.append(str(site.specie), site.coords) xyzObj = XYZ(molecule) os.chdir(dataDir) os.system('mkdir singleMolecule') xyzObj.write_file(dataDir + '/singleMolecule/singleMol.xyz')
def test_adsorb_both_surfaces(self): o = Molecule("O", [[0, 0, 0]]) adslabs = self.asf_100.adsorb_both_surfaces(o) for adslab in adslabs: sg = SpacegroupAnalyzer(adslab) sites = sorted(adslab, key=lambda site: site.frac_coords[2]) self.assertTrue(sites[0].species_string == "O") self.assertTrue(sites[-1].species_string == "O")
def test_apply_transformation(self): co = Molecule(["C", "O"], [[0, 0, 0], [0, 0, 1.23]]) trans = AddAdsorbateTransformation(co) pt = Structure(Lattice.cubic(5), ["Pt"], [[0, 0, 0]]) # fictitious slab = SlabTransformation([0, 0, 1], 20, 10).apply_transformation(pt) out = trans.apply_transformation(slab) self.assertEqual(out.composition.reduced_formula, "Pt4CO")
def test_from_multi_jobs_file(self): job_list_test = QCInput.from_multi_jobs_file( os.path.join(test_dir, "pt_n2_wb97mv_0.0.in")) species = [ "S", "C", "H", "C", "H", "C", "H", "C", "C", "C", "H", "C", "H", "C", "H", "S" ] coords = [[-0.00250959, -0.05817469, -0.02921636], [1.70755408, -0.03033788, -0.01382912], [2.24317221, -0.05215019, 0.92026728], [2.21976393, 0.01718014, -1.27293235], [3.27786220, 0.04082146, -1.48539646], [1.20867399, 0.04478540, -2.27007793], [1.40292257, 0.10591684, -3.33110912], [-0.05341046, 0.01577217, -1.74839343], [-1.32843436, 0.03545064, -2.45531187], [-1.55195156, 0.08743920, -3.80184635], [-0.75245172, 0.10267657, -4.52817967], [-2.93293778, 0.08408786, -4.13352169], [-3.31125108, 0.11340328, -5.14405819], [-3.73173288, 0.02741365, -3.03412864], [-4.80776535, 0.00535688, -2.99564645], [-2.81590978, -0.00516172, -1.58990580]] molecule_1_actual = Molecule(species, coords) rem_1_actual = { "job_type": "opt", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "sad", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } opt_1_actual = {"CONSTRAINT": ["tors 6 8 9 10 0.0"]} self.assertEqual(molecule_1_actual, job_list_test[0].molecule) self.assertEqual(rem_1_actual, job_list_test[0].rem) self.assertEqual(opt_1_actual, job_list_test[0].opt) molecule_2_actual = "read" rem_2_actual = { "job_type": "sp", "method": "wb97m-v", "basis": "def2-tzvppd", "gen_scfman": "true", "geom_opt_max_cycles": "75", "max_scf_cycles": "300", "scf_algorithm": "diis", "scf_guess": "read", "sym_ignore": "true", "symmetry": "false", "thresh": "14" } self.assertEqual(molecule_2_actual, job_list_test[1].molecule) self.assertEqual(rem_2_actual, job_list_test[1].rem)
def test_image(self): s1 = Structure(Lattice.cubic(3.61), ['Mo', 'Mo'], [[0., 0., 0.], [0.5, 0.5, 0.5]]) s2 = Structure(Lattice.cubic(3.61), ['Mo', 'Mo'], [[0., 0., 0.], [0.6, 0.6, 0.5]]) mol1 = Molecule(['C', 'O', 'O'], [[0, 0, 0], [1, 0, 0], [-1, 0, 0]]) mol2 = Molecule(['C', 'O', 'O'], [[0, 0, 0], [2, 0, 0], [-2, 0, 0]]) image1 = Image(s1) image2 = Image(s2) interps = image1.interpolate(image2) self.assertTrue( np.linalg.norm(interps[-2].struct_or_mol.cart_coords - interps[-2].data) < 1e-3) self.assertTrue(isinstance(interps[1].struct_or_mol, Structure)) image1 = Image(mol1) image2 = Image(mol2) interps = image1.interpolate(image2) self.assertTrue( np.linalg.norm(interps[-2].struct_or_mol.cart_coords - interps[-2].data) < 1e-3) self.assertTrue(isinstance(interps[1].struct_or_mol, Molecule)) image1.link_next(image2) self.assertTrue(image2.prev == image1) image3 = Image(image1) self.assertTrue( np.linalg.norm(np.array(image3.data) - np.array(image1.data)) < 1e-3) image4 = Image([1, 2]) image4.update([3, 4]) self.assertListEqual(image4.data, [3, 4]) self.assertTrue(str(image4).startswith("Image with")) image4 = Image([1, 2]) image5 = Image([3, 4]) all_images = image4.interpolate(image5, 3) self.assertEqual(len(all_images), 3) self.assertEqual(str(image4), repr(image4)) image4.struct_or_mol = 1 self.assertEqual(image4.struct_or_mol, 1)
def test_generate_adsorption_structures(self): co = Molecule("CO", [[0, 0, 0], [0, 0, 1.23]]) structures = self.asf_111.generate_adsorption_structures( co, repeat=[2, 2, 1]) self.assertEqual(len(structures), 4) sites = self.asf_111.find_adsorption_sites() # Check repeat functionality self.assertEqual( len([ site for site in structures[0] if site.properties["surface_properties"] != "adsorbate" ]), 4 * len(self.asf_111.slab), ) for n, structure in enumerate(structures): self.assertArrayAlmostEqual(structure[-2].coords, sites["all"][n]) find_args = {"positions": ["hollow"]} structures_hollow = self.asf_111.generate_adsorption_structures( co, find_args=find_args) self.assertEqual(len(structures_hollow), len(sites["hollow"])) for n, structure in enumerate(structures_hollow): self.assertTrue( in_coord_list(sites["hollow"], structure[-2].coords, 1e-4)) # Check molecule not changed after rotation when added to surface co = Molecule("CO", [[1.0, -0.5, 3], [0.8, 0.46, 3.75]]) structures = self.asf_211.generate_adsorption_structures(co) self.assertEqual(co, Molecule("CO", [[1.0, -0.5, 3], [0.8, 0.46, 3.75]])) # Check translation sites = self.asf_211.find_adsorption_sites() ads_site_coords = sites["all"][0] c_site = structures[0].sites[-2] self.assertEqual(str(c_site.specie), "C") self.assertArrayAlmostEqual(c_site.coords, sites["all"][0]) # Check no translation structures = self.asf_111.generate_adsorption_structures( co, translate=False) self.assertEqual(co, Molecule("CO", [[1.0, -0.5, 3], [0.8, 0.46, 3.75]])) sites = self.asf_111.find_adsorption_sites() ads_site_coords = sites["all"][0] c_site = structures[0].sites[-2] self.assertArrayAlmostEqual(c_site.coords, ads_site_coords + np.array([1.0, -0.5, 3]))
def setUp(self): super(TestAdsorptionWorkflow, self).setUp() self.struct_ir = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.875728), ["Ir"], [[0, 0, 0]]) sgp = {"max_index": 1, "min_slab_size": 7.0, "min_vacuum_size": 20.0} slabs = generate_all_slabs(self.struct_ir, **sgp) slabs = [slab for slab in slabs if slab.miller_index==(1, 0, 0)] sgp.pop("max_index") self.wf_1 = get_wf_surface(slabs, [Molecule("H", [[0, 0, 0]])], self.struct_ir, sgp, db_file=os.path.join(db_dir, "db.json"))
def setUp(self): # set up a Structure self.s = Structure(np.eye(3, 3) * 3, ["Fe"], [[0, 0, 0]]) self.s2 = Structure(np.eye(3, 3) * 3, ["Al"], [[0, 0, 0]]) self.mol = Molecule(["He"], [[0, 0, 0]]) # set up BibTeX strings self.matproj = ( "@misc{MaterialsProject,\ntitle = {{Materials " "Project}},\nurl = {http://www.materialsproject.org}\n}") self.pmg = ("@article{Ong2013,\n author = {Ong, " "Shyue Ping and Richards, William Davidson and Jain, " "Anubhav and Hautier, Geoffroy and Kocher, " "Michael and Cholia, Shreyas and Gunter, Dan and Chevrier," " Vincent L. and Persson, Kristin A. and Ceder, Gerbrand}," "\n doi = {10.1016/j.commatsci.2012.10.028}," "\n issn = {09270256},\n journal = {Computational " "Materials Science},\n month = feb,\n pages = {314--319}," "\n publisher = {Elsevier B.V.}," "\n title = {{Python Materials Genomics (pymatgen): A " "robust, open-source python library for materials " "analysis}},\n url = {http://linkinghub.elsevier" ".com/retrieve/pii/S0927025612006295},\n volume = {68}," "\n year = {2013}\n}") repeat = "REPEAT" * 10000 self.superlong = "@misc{SuperLong,\ntitle = {{" + repeat + "}}}" self.unicode_title = "@misc{Unicode_Title,\ntitle = {{A \u73ab is a rose}}}" self.junk = "This is junk text, not a BibTeX reference" # set up remarks self.remark_fail = [ "This is a really long remark that is clearly invalid and must fail, don't you agree? It would be silly " "to allow remarks that went on forever and ever." ] # set up some authors self.hulk = [{"name": "Hulk", "email": "*****@*****.**"}] self.america = "Captain America <*****@*****.**>" self.thor = [("Thor", "*****@*****.**")] self.duo = ("Iron Man <*****@*****.**>, " "Black Widow <*****@*****.**>") # set up HistoryNodes self.valid_node = HistoryNode("DB 1", "www.db1URLgoeshere.com", {"db1_id": 12424}) self.valid_node2 = { "name": "DB 2", "url": "www.db2URLgoeshere.com", "description": { "db2_id": 12424 }, } self.invalid_node = { "name": "DB 3", "url": "http://www.db3isnotavalidnode.com" }