def test_localopt(self): self.mol[1] = "H", [0, 0, 1.05] adaptor = BabelMolAdaptor(self.mol) adaptor.localopt() optmol = adaptor.pymatgen_mol for site in optmol[1:]: self.assertAlmostEqual(site.distance(optmol[0]), 1.09216, 1)
def test_localopt(self): self.mol[1] = "H", [0, 0, 1.05] adaptor = BabelMolAdaptor(self.mol) adaptor.localopt() optmol = adaptor.pymatgen_mol for site in optmol[1:]: self.assertAlmostEqual(site.distance(optmol[0]), 1.09216, 2)
def addh(self, mol): #if len(mol) < len(self.ref_mol): from pymatgen.io.babel import BabelMolAdaptor ad = BabelMolAdaptor(mol) ad.add_hydrogen() ad.localopt() mol = ad.pymatgen_mol return mol
def addh(self, molecules): """ add hydrogen """ from pymatgen.io.babel import BabelMolAdaptor for mol in molecules: ad = BabelMolAdaptor(mol) ad.add_hydrogen() ad.localopt() mol = ad.pymatgen_mol return molecules
def __init__(self, molecule, optimize=False): """ Instantiation method for FunctionalGroupExtractor. :param molecule: Either a filename, a pymatgen.core.structure.Molecule object, or a pymatgen.analysis.graphs.MoleculeGraph object. :param optimize: Default False. If True, then the input molecule will be modified, adding Hydrogens, performing a simple conformer search, etc. """ self.molgraph = None if isinstance(molecule, str): try: if optimize: obmol = BabelMolAdaptor.from_file(molecule, file_format="mol") # OBMolecule does not contain pymatgen Molecule information # So, we need to wrap the obmol in a BabelMolAdapter obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = Molecule.from_file(molecule) except OSError: raise ValueError("Input must be a valid molecule file, a " "Molecule object, or a MoleculeGraph object.") elif isinstance(molecule, Molecule): if optimize: obmol = BabelMolAdaptor(molecule) obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = molecule elif isinstance(molecule, MoleculeGraph): if optimize: obmol = BabelMolAdaptor(molecule.molecule) obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = molecule.molecule self.molgraph = molecule else: raise ValueError("Input to FunctionalGroupExtractor must be" "str, Molecule, or MoleculeGraph.") if self.molgraph is None: self.molgraph = MoleculeGraph.with_local_env_strategy( self.molecule, OpenBabelNN(), reorder=False, extend_structure=False) # Assign a specie and coordinates to each node in the graph, # corresponding to the Site in the Molecule object self.molgraph.set_node_attributes() self.species = nx.get_node_attributes(self.molgraph.graph, "specie")
def __init__(self, molecule, optimize=False): """ Instantiation method for FunctionalGroupExtractor. :param molecule: Either a filename, a pymatgen.core.structure.Molecule object, or a pymatgen.analysis.graphs.MoleculeGraph object. :param optimize: Default False. If True, then the input molecule will be modified, adding Hydrogens, performing a simple conformer search, etc. """ self.molgraph = None if isinstance(molecule, str): try: if optimize: obmol = BabelMolAdaptor.from_file(molecule, file_format="mol") # OBMolecule does not contain pymatgen Molecule information # So, we need to wrap the obmol in a BabelMolAdapter obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = Molecule.from_file(molecule) except OSError: raise ValueError("Input must be a valid molecule file, a " "Molecule object, or a MoleculeGraph object.") elif isinstance(molecule, Molecule): if optimize: obmol = BabelMolAdaptor(molecule) obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = molecule elif isinstance(molecule, MoleculeGraph): if optimize: obmol = BabelMolAdaptor(molecule.molecule) obmol.add_hydrogen() obmol.make3d() obmol.localopt() self.molecule = obmol.pymatgen_mol else: self.molecule = molecule.molecule self.molgraph = molecule else: raise ValueError("Input to FunctionalGroupExtractor must be" "str, Molecule, or MoleculeGraph.") if self.molgraph is None: self.molgraph = MoleculeGraph.with_local_env_strategy(self.molecule, OpenBabelNN(), reorder=False, extend_structure=False) # Assign a specie and coordinates to each node in the graph, # corresponding to the Site in the Molecule object self.molgraph.set_node_attributes() self.species = nx.get_node_attributes(self.molgraph.graph, "specie")
break print("Indices (in molecule) of atoms to be substituted are: ", end='') print(substitute_sitelist) """ Do the actual substitution, first-order force-field structure clean-up and store derivatives in dictionary "derivatives" (name as key and molecule object as value). """ derivatives = {} for index in substitute_sitelist: for func_grp in FunctionalGroups(): name = str(index) + "_" + func_grp mol2 = mol.copy() mol2.substitute(index, func_grp) a = BabelMolAdaptor(mol2) a.localopt() derivatives[name] = a.pymatgen_mol print("Total of ", end='') print(len(list(derivatives.keys())), end='') print(" derivatives are created") ''' Mol to WF ''' module_dir = os.path.dirname(os.path.abspath(__file__)) for name in derivatives: print(name) wf = mol_to_wf_nwchem(derivatives[name], name) wf.to_file(os.path.join(module_dir, 'thiane_wfs', name + '.yaml'))