Пример #1
0
def min_ffxml(mol, ofs, ffxml):
    """
    Minimize the mol with force field input from FFXML file.

    Parameters
    ----------
    mol : OpenEye single-conformer molecule
    ofs : OpenEye output filestream
    ffxml : string
        name of FFXML file

    """

    # make copy of the input mol
    oe_mol = oechem.OEGraphMol(mol)

    try:
        # create openforcefield molecule ==> prone to triggering Exception
        off_mol = Molecule.from_openeye(oe_mol)

        # load in force field
        ff = ForceField(ffxml)

        # create components for OpenMM system
        topology = Topology.from_molecules(molecules=[off_mol])

        # create openmm system ==> prone to triggering Exception
        #system = ff.create_openmm_system(topology, charge_from_molecules=[off_mol])
        system = ff.create_openmm_system(topology)

    except Exception as e:
        smilabel = oechem.OEGetSDData(oe_mol, "SMILES QCArchive")
        print( ' >>> openforcefield failed to create OpenMM system: '
               f'{oe_mol.GetTitle()} {smilabel}: {e}')
        return

    positions = structure.extractPositionsFromOEMol(oe_mol)

    # minimize structure with ffxml
    newpos, energy = run_openmm(topology, system, positions)

    # save geometry, save energy as tag, write mol to file
    oe_mol.SetCoords(oechem.OEFloatArray(newpos))
    oechem.OESetSDData(oe_mol, "Energy FFXML", str(energy))
    oechem.OEWriteConstMolecule(ofs, oe_mol)

    return
def test_merge_system():
    """Test merging of a system created from AMBER and another created from SMIRNOFF."""
    from .utils import create_system_from_amber, get_amber_file_path, get_alkethoh_file_path

    # Create System from AMBER
    prmtop_filename, inpcrd_filename = get_amber_file_path(
        'cyclohexane_ethanol_0.4_0.6')
    system0, topology0, positions0 = create_system_from_amber(
        prmtop_filename, inpcrd_filename)

    # TODO:
    from openeye import oechem
    # Load simple OEMol
    alkethoh_mol2_filepath = get_alkethoh_file_path('AlkEthOH_c100')[0]
    ifs = oechem.oemolistream(alkethoh_mol2_filepath)
    mol = oechem.OEMol()
    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)

    # Load forcefield file.
    AlkEthOH_offxml_filename = utils.get_data_file_path(
        'test_forcefields/Frosst_AlkEthOH.offxml')
    forcefield = ForceField(AlkEthOH_offxml_filename)

    # Create OpenMM System and Topology.
    off_mol = Molecule.from_openeye(mol, allow_undefined_stereo=True)
    off_top = Topology.from_molecules([off_mol])
    system1 = forcefield.create_openmm_system(off_top)
    topology1 = structure.generateTopologyFromOEMol(mol)
    positions1 = structure.extractPositionsFromOEMol(mol)

    structure.merge_system(topology0,
                           topology1,
                           system0,
                           system1,
                           positions0,
                           positions1,
                           verbose=True)
 def test_positions(self):
     """Test ability to extract and set positions."""
     molecules = structure.read_molecules('zinc-subset-tripos.mol2.gz',
                                          verbose=False)
     positions = structure.extractPositionsFromOEMol(molecules[0])
     structure.setPositionsInOEMol(molecules[0], positions)