def test_undefined_stereo(self): """ It checks the behaviour when ignoring the stereochemistry in the Molecule initialization. """ from openff.toolkit.utils.toolkits import UndefinedStereochemistryError from peleffy.forcefield import OpenForceField # This should crash due to an undefined stereochemistry error with pytest.raises(UndefinedStereochemistryError): mol = Molecule(smiles='CN(C)CCC=C1c2ccccc2CCc3c1cccc3', hydrogens_are_explicit=False) # This now should work mol = Molecule(smiles='CN(C)CCC=C1c2ccccc2CCc3c1cccc3', allow_undefined_stereo=True, hydrogens_are_explicit=False) # And we can parameterize it ff = OpenForceField('openff_unconstrained-1.2.1.offxml') ff.parameterize(mol, charge_method='gasteiger') # Save it with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): mol.to_pdb_file('molecule.pdb')
def test_PDB_residue_name(self): """ It tests the PDB residue name and checks for consistency with Molecule tag. """ def check_residue_name(name): """Check if residue names are valid in the output PDB file""" with open('molecule.pdb') as f: for line in f: if line.startswith('HETATM'): assert line[17:20] == name, 'Unexpected residue name' ligand_path = get_data_file_path('ligands/benzene.pdb') # Checking tag assignation from PDB molecule = Molecule(ligand_path) with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): assert molecule.tag == 'BNZ', 'Unexpected molecule tag' molecule.to_pdb_file('molecule.pdb') check_residue_name('BNZ') # Checking set_tag() function molecule = Molecule(ligand_path) with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): molecule.set_tag('TAG') assert molecule.tag == 'TAG', 'Unexpected molecule tag' molecule.to_pdb_file('molecule.pdb') check_residue_name('TAG') # Checking default tag assignment from SMILES molecule = Molecule(smiles='c1ccccc1', hydrogens_are_explicit=False) with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): assert molecule.tag == 'UNK', 'Unexpected molecule tag' molecule.to_pdb_file('molecule.pdb') check_residue_name('UNK') # Checking custom tag assignment from SMILES molecule = Molecule(smiles='c1ccccc1', tag='BEN', hydrogens_are_explicit=False) with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): assert molecule.tag == 'BEN', 'Unexpected molecule tag' molecule.to_pdb_file('molecule.pdb') check_residue_name('BEN') # Checking second custom tag assignment from SMILES molecule = Molecule(smiles='c1ccccc1', hydrogens_are_explicit=False) with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): molecule.set_tag('BNZ') assert molecule.tag == 'BNZ', 'Unexpected molecule tag' molecule.to_pdb_file('molecule.pdb') check_residue_name('BNZ')
def test_smiles_initialization(self): """ It checks the initialization from a SMILES tag. """ molecule = Molecule(smiles='c1ccccc1', hydrogens_are_explicit=False) # Save it with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): molecule.to_pdb_file('molecule.pdb')
def test_pdb_initialization(self): """ It checks the initialization from a PDB file. """ ligand_path = get_data_file_path('ligands/ethylene.pdb') molecule = Molecule(ligand_path) # Save it with tempfile.TemporaryDirectory() as tmpdir: with temporary_cd(tmpdir): molecule.to_pdb_file('molecule.pdb')
def _generate_parameters(self, smiles, mol_id, output_path, forcefield='openff_unconstrained-1.2.0.offxml', charges_method='am1bcc'): """ It generates the parameters of the molecule (from the input_file) as DataLocal in the output folder. Parameters ---------- smiles : str The smiles tag representing the molecule to minimize mol_id : str Unique id to identify the molecule to minimize output_path : str The output path where parameters will be saved forcefield : str The Open Force Field force field to generate the parameters with charges_method : str The charges method to calculate the partial charges with """ import peleffy from peleffy.topology import Molecule from peleffy.template import Impact from peleffy.solvent import OBC2 from peleffy.main import handle_output_paths import os # Create representation of a particular molecule molecule = Molecule(smiles=smiles, name=mol_id, tag='UNL') # Save molecule to PDB file molecule.to_pdb_file(os.path.join(output_path, 'ligand.pdb')) # Saving paths rotamer_library_output_path, impact_output_path, \ solvent_output_path = handle_output_paths(molecule=molecule, output=output_path, as_datalocal=True) # Generate its rotamer library rotamer_library = peleffy.topology.RotamerLibrary(molecule) rotamer_library.to_file(rotamer_library_output_path) # Generate its parameters and template file molecule.parameterize(forcefield, charges_method=charges_method) impact = Impact(molecule) impact.write(impact_output_path) # Generate its solvent parameters solvent = OBC2(molecule) solvent.to_json_file(solvent_output_path)