def test_from_toolkit_packmol_boxes(self, pdb_path, unique_molecules): """ Test loading some pre-prepared PACKMOL-generated systems. These use PDB files already prepared in the toolkit because PDB files are a pain. """ ff = ForceField("openff-1.0.0.offxml") pdb_file_path = get_data_file_path("systems/packmol_boxes/" + pdb_path) pdbfile = openmm.app.PDBFile(pdb_file_path) top = Topology.from_openmm( pdbfile.topology, unique_molecules=unique_molecules, ) box = pdbfile.topology.getPeriodicBoxVectors() box = box.value_in_unit(nm) * unit.nanometer out = ff.create_openff_system(top) out.box = box out.positions = pdbfile.getPositions() assert np.allclose( out.positions.to(unit.nanometer).magnitude, pdbfile.getPositions().value_in_unit(nm), ) get_openmm_energies(out, hard_cutoff=True).compare( _get_openmm_energies( omm_sys=ff.create_openmm_system(top), box_vectors=pdbfile.topology.getPeriodicBoxVectors(), positions=pdbfile.getPositions(), hard_cutoff=True, ))
def test_unsupported_handler(self): from openff.system.stubs import ForceField gbsa_ff = ForceField( get_data_file_path("test_forcefields/GBSA_HCT-1.0.offxml")) with pytest.raises(SMIRNOFFHandlersNotImplementedError, match=r"SMIRNOFF parameters not.*GBSA"): gbsa_ff.create_openff_system(topology=None)
def test_from_toolkit_packmol_boxes(self, pdb_path, unique_molecules): """ Test loading some pre-prepared PACKMOL-generated systems. These use PDB files already prepared in the toolkit because PDB files are a pain. """ pdb_file_path = get_data_file_path("systems/packmol_boxes/" + pdb_path) pdbfile = openmm.app.PDBFile(pdb_file_path) Topology.from_openmm( pdbfile.topology, unique_molecules=unique_molecules, )
def setup_class(cls): cls.thing = Thing("blorb", [1, 2, 3]) # Create an example object holding the SMIRNOFF xmltodict dictionary representation import xmltodict from openff.toolkit.utils import get_data_file_path filename = get_data_file_path("test_forcefields/test_forcefield.offxml") with open(filename, "r") as f: xml = f.read() dictionary = xmltodict.parse(xml) cls.thing = DictionaryContainer(dictionary)
def run_script_file(file_path): """Run through the shell a python script.""" with tempfile.TemporaryDirectory() as tmp_dir: with temporary_cd(tmp_dir): cmd = ["python", file_path] if "conformer_energies.py" in file_path: cmd.append("--filename") mol_file = get_data_file_path( "molecules/ruxolitinib_conformers.sdf") cmd.append(mol_file) try: subprocess.check_call(cmd) except subprocess.CalledProcessError: raise Exception(f"Example {file_path} failed")
def untar_full_alkethoh_and_freesolv_set(): """When running slow tests, we unpack the full AlkEthOH and FreeSolv test sets in advance to speed things up. See test_forcefield.py::test_alkethoh_parameters_assignment test_forcefield.py::test_freesolv_parameters_assignment """ import os import tarfile from openff.toolkit.utils import get_data_file_path molecule_dir_path = get_data_file_path("molecules") for tarfile_name in ["AlkEthOH_tripos.tar.gz", "FreeSolv.tar.gz"]: tarfile_path = os.path.join(molecule_dir_path, tarfile_name) with tarfile.open(tarfile_path, "r:gz") as tar: tar.extractall(path=molecule_dir_path)
mol_filename = 'ETH.mol2' # Define a few simulation parameters time_step = 2 * unit.femtoseconds # simulation timestep temperature = 300 * unit.kelvin # simulation temperature friction = 1 / unit.picosecond # collision rate num_steps = 1000000 # number of steps to run trj_freq = 1000 # number of steps per written trajectory frame data_freq = 1000 # number of steps per written simulation statistics # Load molecule and create pdb object pdb = PDBFile(pdb_filename) # Load a SMIRNOFF force field forcefield = ForceField( get_data_file_path('test_forcefields/Frosst_AlkEthOH_parmAtFrosst.offxml')) # Load molecule using OpenEye tools mol = oechem.OEGraphMol() ifs = oechem.oemolistream(mol_filename) # LPW: I don't understand the meaning of these lines. # flavor = oechem.OEIFlavor_Generic_Default | oechem.OEIFlavor_MOL2_Default | oechem.OEIFlavor_MOL2_Forcefield # ifs.SetFlavor( oechem.OEFormat_MOL2, flavor) oechem.OEReadMolecule(ifs, mol) oechem.OETriposAtomNames(mol) # Create the OpenMM system system = forcefield.createSystem(pdb.topology, [mol], nonbondedMethod=PME, nonbondedCutoff=1.0 * unit.nanometers, rigidWater=True)
def test_get_data_file_path(): """Test get_data_file_path()""" from openff.toolkit.utils import get_data_file_path filename = get_data_file_path("test_forcefields/tip3p.offxml") assert os.path.exists(filename)
"DrugBank_4662", "DrugBank_7108", "DrugBank_7124", "DrugBank_2140", "DrugBank_2148", "DrugBank_2186", "DrugBank_2237", "DrugBank_4959", "DrugBank_2429", "DrugBank_5154", "DrugBank_2563", "DrugBank_2570", "DrugBank_2584", "DrugBank_2585", "DrugBank_2684", ] mini_drug_bank = Molecule.from_file( get_data_file_path("molecules/MiniDrugBank.sdf"), allow_undefined_stereo=True) mols = [mol for mol in mini_drug_bank if mol.name in trimmed_mol_names] with Chem.SDWriter("MiniDrugBankTrimmed.sdf") as f: for openff_mol in mols: try: openff_mol.assign_partial_charges(partial_charge_method="am1bcc") rdmol = openff_mol.to_rdkit() except: # noqa continue f.write(rdmol)
def test_packmol_boxes(toolkit_file_path): # TODO: Isolate a set of systems here instead of using toolkit data # TODO: Fix nonbonded energy differences from openff.toolkit.utils import get_data_file_path pdb_file_path = get_data_file_path(toolkit_file_path) pdbfile = openmm.app.PDBFile(pdb_file_path) ethanol = Molecule.from_smiles("CCO") cyclohexane = Molecule.from_smiles("C1CCCCC1") omm_topology = pdbfile.topology off_topology = Topology.from_openmm( omm_topology, unique_molecules=[ethanol, cyclohexane] ) parsley = ForceField("openff_unconstrained-1.0.0.offxml") off_sys = parsley.create_openff_system(off_topology) off_sys.box = np.asarray( pdbfile.topology.getPeriodicBoxVectors() / omm_unit.nanometer, ) off_sys.positions = np.asarray( pdbfile.positions / omm_unit.nanometer, ) sys_from_toolkit = parsley.create_openmm_system(off_topology) omm_energies = get_openmm_energies(off_sys, hard_cutoff=True, electrostatics=False) reference = _get_openmm_energies( sys_from_toolkit, off_sys.box, off_sys.positions, hard_cutoff=True, electrostatics=False, ) omm_energies.compare( reference, custom_tolerances={ "Nonbonded": 2e-2 * omm_unit.kilojoule_per_mole, }, ) # custom_tolerances={"HarmonicBondForce": 1.0} # Compare GROMACS writer and OpenMM export gmx_energies = get_gromacs_energies(off_sys, electrostatics=False) omm_energies_rounded = get_openmm_energies( off_sys, round_positions=8, hard_cutoff=True, electrostatics=False, ) omm_energies_rounded.compare( other=gmx_energies, custom_tolerances={ "Angle": 1e-2 * omm_unit.kilojoule_per_mole, "Torsion": 1e-2 * omm_unit.kilojoule_per_mole, "Nonbonded": 3200 * omm_unit.kilojoule_per_mole, }, )
#!/bin/env python """ Illustrate how to combine a SMIRNOFF parameterized small molecule with an AMBER parameterized protein using ParmEd. """ # # Load and parameterize the small molecule # # Load the small molecule from openff.toolkit.utils import get_data_file_path ligand_filename = get_data_file_path('molecules/toluene.mol2') molecule = Molecule.from_file(ligand_filename) # Load the smirnoff99Frosst force field from openff.toolkit.typing.engines import smirnoff forcefield = smirnoff.ForceField('test_forcefields/test_forcefield.offxml') # Create a ParmEd structure for the molecule molecule_structure = forcefield.create_parmed_structure( topology=molecule.to_topology(), positions=molecule.positions) print('Molecule:', molecule_structure) # # Load and parameterize the protein # # Load the protein topology protein_pdb_filename = get_data_file_path('proteins/T4-protein.pdb') protein_pdbfile = app.PDBFile(protein_pdb_filename)