Пример #1
0
 def testLoadAmberMdcrd(self):
     """ Tests automatic loading of Amber mdcrd file """
     crd = formats.load_file(get_fn('tz2.truncoct.crd'), natom=5827,
                             hasbox=True)
     self.assertIsInstance(crd, amber.AmberMdcrd)
     self.assertRaises(TypeError, lambda:
             formats.load_file(get_fn('tz2.truncoct.crd')))
Пример #2
0
 def testLoadNetCDFTraj(self):
     """ Tests automatic loading of Amber NetCDF trajectory file """
     if amber.HAS_NETCDF:
         crd = formats.load_file(get_fn('tz2.truncoct.nc'))
         self.assertIsInstance(crd, amber.NetCDFTraj)
     else:
         self.assertRaises(exceptions.FormatNotFound, lambda:
                 formats.load_file(get_fn('ncinpcrd.rst7')))
Пример #3
0
 def testLoadNetCDFRestart(self):
     """ Tests automatic loading of Amber NetCDF restart file """
     if amber.HAS_NETCDF:
         crd = formats.load_file(get_fn('ncinpcrd.rst7'))
         self.assertIsInstance(crd, amber.NetCDFRestart)
     else:
         self.assertRaises(exceptions.FormatNotFound, lambda:
                 formats.load_file(get_fn('ncinpcrd.rst7')))
Пример #4
0
 def testDownloadAmoebaParm(self):
     """ Tests automatic loading of downloaded AmoebaParm object """
     parm = formats.load_file(self.url + 'nma.parm7')
     self.assertIsInstance(parm, amber.AmoebaParm)
Пример #5
0
 def testLoadGromacsTop(self):
     """ Tests automatic loading of Gromacs topology file """
     top = formats.load_file(get_fn('1aki.charmm27.top'))
     self.assertIsInstance(top, gromacs.GromacsTopologyFile)
Пример #6
0
 def testDownloadGromacsGro(self):
     """ Tests automatic loading of downloaded Gromacs GRO file """
     gro = formats.load_file(self.url + '1aki.ff99sbildn.gro')
     self.assertIsInstance(gro, Structure)
Пример #7
0
 def testDownloadMol2(self):
     """ Tests automatic loading of downloaded mol2 and mol3 files """
     mol2 = formats.load_file(self.url + 'test_multi.mol2')
     self.assertIsInstance(mol2, ResidueTemplateContainer)
     mol3 = formats.load_file(self.url + 'tripos9.mol2')
     self.assertIsInstance(mol3, ResidueTemplate)
Пример #8
0
 def testDownloadPDB(self):
     """ Tests automatic loading of downloaded PDB files """
     pdb = formats.load_file(self.url + '4lzt.pdb')
     self.assertIsInstance(pdb, Structure)
     self.assertEqual(len(pdb.atoms), 1164)
Пример #9
0
 def testBadLoads(self):
     """ Test exception handling when non-recognized files are loaded """
     self.assertRaises(exceptions.FormatNotFound, lambda:
             formats.load_file(get_fn('../test_parmed_formats.py')))
     self.assertRaises(IOError, lambda: formats.load_file('no_file'))
Пример #10
0
 def testDownloadAmberRestart(self):
     """ Tests automatic loading of downloaded Amber ASCII restart file """
     parm = formats.load_file(self.url + 'trx.inpcrd')
     self.assertIsInstance(parm, amber.AmberAsciiRestart)
Пример #11
0
 def testLoadAmberRestart(self):
     """ Tests automatic loading of Amber ASCII restart file """
     parm = formats.load_file(get_fn('trx.inpcrd'))
     self.assertIsInstance(parm, amber.AmberAsciiRestart)
Пример #12
0
 def testLoadAmberFormat(self):
     """ Tests automatic loading of RISM mdl (AmberFormat) object """
     parm = formats.load_file(get_fn('cSPCE.mdl'))
     self.assertIsInstance(parm, amber.AmberFormat)
     self.assertNotIsInstance(parm, amber.AmberParm)
Пример #13
0
 def testLoadChamberParm(self):
     """ Tests automatic loading of ChamberParm object """
     parm = formats.load_file(get_fn('ala_ala_ala.parm7'))
     self.assertIsInstance(parm, amber.ChamberParm)
Пример #14
0
 def testLoadAmoebaParm(self):
     """ Tests automatic loading of AmoebaParm object """
     parm = formats.load_file(get_fn('amoeba.parm7'))
     self.assertIsInstance(parm, amber.AmoebaParm)
Пример #15
0
 def testLoadAmberParm(self):
     """ Tests automatic loading of AmberParm object """
     parm = formats.load_file(get_fn('trx.prmtop'))
     self.assertIsInstance(parm, amber.AmberParm)
Пример #16
0
 def testStructureKeyword(self):
     """ Tests that the structure argument is special-cased in load_file """
     mol2 = formats.load_file(get_fn('tripos9.mol2'), structure=True)
     self.assertIsInstance(mol2, Structure)
     pdb = formats.load_file(get_fn('4lzt.pdb'), structure=True)
Пример #17
0
 def testDownloadChamberParm(self):
     """ Tests automatic loading of downloaded ChamberParm object """
     parm = formats.load_file(self.url + 'ala_ala_ala.parm7')
     self.assertIsInstance(parm, amber.ChamberParm)
Пример #18
0
 def testDownloadAmberFormat(self):
     """ Tests automatic loading of downloaded AmberFormat object """
     parm = formats.load_file(self.url + 'cSPCE.mdl')
     self.assertIsInstance(parm, amber.AmberFormat)
     self.assertNotIsInstance(parm, amber.AmberParm)
Пример #19
0
 def testDownloadAmberMdcrd(self):
     """ Tests automatic loading of downloaded Amber mdcrd file """
     crd = formats.load_file(self.url + 'tz2.truncoct.crd', natom=5827,
                             hasbox=True)
     self.assertIsInstance(crd, amber.AmberMdcrd)
Пример #20
0
 def testDownloadCharmmCrdFile(self):
     """ Tests automatic loading of downloaded CHARMM crd file """
     crd = formats.load_file(self.url + 'dhfr_min_charmm.crd')
     self.assertIsInstance(crd, charmm.CharmmCrdFile)
Пример #21
0
 def testLoadGromacsGro(self):
     """ Tests automatic loading of Gromacs GRO file """
     gro = formats.load_file(get_fn('1aki.ff99sbildn.gro'))
     self.assertIsInstance(gro, Structure)
Пример #22
0
 def testDownloadCharmmPsfFile(self):
     """ Tests automatic loading of downloaded CHARMM PSF file """
     parm = formats.load_file(self.url + 'ala_ala_ala.psf')
     self.assertIsInstance(parm, charmm.CharmmPsfFile)
Пример #23
0
 def testLoadCharmmPsfFile(self):
     """ Tests automatic loading of CHARMM PSF file """
     parm = formats.load_file(get_fn('ala_ala_ala.psf'))
     self.assertIsInstance(parm, charmm.CharmmPsfFile)
Пример #24
0
 def testDownloadCharmmRestart(self):
     """ Tests automatic loading of downloaded CHARMM restart file """
     crd = formats.load_file(self.url + 'sample-charmm.rst')
     self.assertIsInstance(crd, charmm.CharmmRstFile)
Пример #25
0
 def testLoadCharmmCrdFile(self):
     """ Tests automatic loading of CHARMM crd file """
     crd = formats.load_file(get_fn('dhfr_min_charmm.crd'))
     self.assertIsInstance(crd, charmm.CharmmCrdFile)
Пример #26
0
 def testDownloadCIF(self):
     """ Tests automatic loading of downloaded PDBx/mmCIF files """
     cif = formats.load_file(self.url + '4LZT.cif')
     self.assertIsInstance(cif, Structure)
     self.assertEqual(len(cif.atoms), 1164)
Пример #27
0
 def testLoadCharmmRestart(self):
     """ Tests automatic loading of CHARMM restart file """
     crd = formats.load_file(get_fn('sample-charmm.rst'))
     self.assertIsInstance(crd, charmm.CharmmRstFile)
Пример #28
0
 def testDownloadGromacsTop(self):
     """ Tests automatic loading of downloaded Gromacs topology file """
     top = formats.load_file(self.url + '1aki.charmm27.top')
     self.assertIsInstance(top, gromacs.GromacsTopologyFile)
Пример #29
0
 def testDownloadOFF(self):
     """ Tests automatic loading of downloaded OFF files """
     off = formats.load_file(self.url + 'amino12.lib')
     self.assertIsInstance(off, dict)
     for key, item in iteritems(off):
         self.assertIsInstance(item, ResidueTemplate)
Пример #30
0
def load_topology(topology, system=None, xyz=None, box=None):
    """
    Creates a :class:`parmed.structure.Structure` instance from an OpenMM
    Topology, optionally filling in parameters from a System

    Parameters
    ----------
    topology : :class:`simtk.openmm.app.Topology`
        The Topology instance with the list of atoms and bonds for this system
    system : :class:`simtk.openmm.System` or str, optional
        If provided, parameters from this System will be applied to the
        Structure. If a string is given, it will be interpreted as the file name
        of an XML-serialized System, and it will be deserialized into a System
        before used to supply parameters
    xyz : str or array of float
        Name of a file containing coordinate information or an array of
        coordinates. If file has unit cell information, it also uses that
        information unless ``box`` (below) is also specified
    box : array of 6 floats
        Unit cell dimensions

    Returns
    -------
    struct : :class:`Structure <parmed.structure.Structure>`
        The structure from the provided topology

    Raises
    ------
    OpenMMWarning if parameters are found that cannot be interpreted or
    processed by ParmEd

    TypeError if there are any mismatches between the provided topology and
    system (e.g., they have different numbers of atoms)

    IOError if system is a string and it is not an existing file

    Notes
    -----
    Due to its flexibility with CustomForces, it is entirely possible that the
    functional form of the potential will be unknown to ParmEd. This function
    will try to use the energy expression to identify supported potential types
    that are implemented as CustomForce objects. In particular, quadratic
    improper torsions, when recognized, will be extracted.

    Other CustomForces, including the CustomNonbondedForce used to implement
    NBFIX (off-diagonal L-J modifications) and the 12-6-4 potential, will not be
    processed and will result in an unknown functional form
    """
    import simtk.openmm as mm
    struct = Structure()
    atommap = dict()
    for c in topology.chains():
        chain = c.id
        for r in c.residues():
            residue = r.name
            resid = r.index
            for a in r.atoms():
                if a.element is None:
                    atom = ExtraPoint(name=a.name)
                else:
                    atom = Atom(atomic_number=a.element.atomic_number,
                                name=a.name, mass=a.element.mass)
                struct.add_atom(atom, residue, resid, chain)
                atommap[a] = atom
    for a1, a2 in topology.bonds():
        struct.bonds.append(Bond(atommap[a1], atommap[a2]))

    vectors = topology.getPeriodicBoxVectors()
    if vectors is not None:
        leng, ang = box_vectors_to_lengths_and_angles(*vectors)
        leng = leng.value_in_unit(u.angstroms)
        ang = ang.value_in_unit(u.degrees)
        struct.box = [leng[0], leng[1], leng[2], ang[0], ang[1], ang[2]]

    loaded_box = False

    if xyz is not None:
        if isinstance(xyz, string_types):
            xyz = load_file(xyz, skip_bonds=True)
            struct.coordinates = xyz.coordinates
            if struct.box is not None:
                if xyz.box is not None:
                    loaded_box = True
                    struct.box = xyz.box
        else:
            struct.coordinates = xyz

    if box is not None:
        loaded_box = True
        struct.box = box

    if struct.box is not None:
        struct.box = np.asarray(struct.box)

    if system is None:
        return struct

    if isinstance(system, string_types):
        system = load_file(system)

    if not isinstance(system, mm.System):
        raise TypeError('system must be an OpenMM System object or serialized '
                        'XML of an OpenMM System object')

    # We have a system, try to extract parameters from it
    if len(struct.atoms) != system.getNumParticles():
        raise TypeError('Topology and System have different numbers of atoms '
                '(%d vs. %d)' % (len(struct.atoms), system.getNumParticles()))

    processed_forces = set()
    ignored_forces = (mm.CMMotionRemover, mm.AndersenThermostat,
                      mm.MonteCarloBarostat, mm.MonteCarloAnisotropicBarostat,
                      mm.MonteCarloMembraneBarostat, mm.CustomExternalForce,
                      mm.GBSAOBCForce, mm.CustomGBForce)

    if system.usesPeriodicBoundaryConditions():
        if not loaded_box:
            vectors = system.getDefaultPeriodicBoxVectors()
            leng, ang = box_vectors_to_lengths_and_angles(*vectors)
            leng = leng.value_in_unit(u.angstroms)
            ang = ang.value_in_unit(u.degrees)
            struct.box = np.asarray(
                    [leng[0], leng[1], leng[2], ang[0], ang[1], ang[2]]
            )
    else:
        struct.box = None

    for force in system.getForces():
        if isinstance(force, mm.HarmonicBondForce):
            if mm.HarmonicBondForce in processed_forces:
                # Try to process this HarmonicBondForce as a Urey-Bradley term
                _process_urey_bradley(struct, force)
            else:
                _process_bond(struct, force)
        elif isinstance(force, mm.HarmonicAngleForce):
            _process_angle(struct, force)
        elif isinstance(force, mm.PeriodicTorsionForce):
            _process_dihedral(struct, force)
        elif isinstance(force, mm.RBTorsionForce):
            _process_rbtorsion(struct, force)
        elif isinstance(force, mm.CustomTorsionForce):
            if not _process_improper(struct, force):
                struct.unknown_functional = True
                warnings.warn('Unknown functional form of CustomTorsionForce',
                              OpenMMWarning)
        elif isinstance(force, mm.CMAPTorsionForce):
            _process_cmap(struct, force)
        elif isinstance(force, mm.NonbondedForce):
            _process_nonbonded(struct, force)
        elif isinstance(force, ignored_forces):
            continue
        else:
            struct.unknown_functional = True
            warnings.warn('Unsupported Force type %s' % type(force).__name__,
                          OpenMMWarning)
        processed_forces.add(type(force))

    return struct
Пример #31
0
def load_topology(topology, system=None, xyz=None, box=None):
    """
    Creates a :class:`parmed.structure.Structure` instance from an OpenMM
    Topology, optionally filling in parameters from a System

    Parameters
    ----------
    topology : :class:`simtk.openmm.app.Topology`
        The Topology instance with the list of atoms and bonds for this system
    system : :class:`simtk.openmm.System` or str, optional
        If provided, parameters from this System will be applied to the
        Structure. If a string is given, it will be interpreted as the file name
        of an XML-serialized System, and it will be deserialized into a System
        before used to supply parameters
    xyz : str or array of float
        Name of a file containing coordinate information or an array of
        coordinates. If file has unit cell information, it also uses that
        information unless ``box`` (below) is also specified
    box : array of 6 floats
        Unit cell dimensions

    Returns
    -------
    struct : :class:`Structure <parmed.structure.Structure>`
        The structure from the provided topology

    Raises
    ------
    OpenMMWarning if parameters are found that cannot be interpreted or
    processed by ParmEd

    TypeError if there are any mismatches between the provided topology and
    system (e.g., they have different numbers of atoms)

    IOError if system is a string and it is not an existing file

    Notes
    -----
    Due to its flexibility with CustomForces, it is entirely possible that the
    functional form of the potential will be unknown to ParmEd. This function
    will try to use the energy expression to identify supported potential types
    that are implemented as CustomForce objects. In particular, quadratic
    improper torsions, when recognized, will be extracted.

    Other CustomForces, including the CustomNonbondedForce used to implement
    NBFIX (off-diagonal L-J modifications) and the 12-6-4 potential, will not be
    processed and will result in an unknown functional form
    """
    import simtk.openmm as mm
    struct = Structure()
    atommap = dict()
    for c in topology.chains():
        chain = c.id
        for r in c.residues():
            residue = r.name
            resid = r.index
            for a in r.atoms():
                if a.element is None:
                    atom = ExtraPoint(name=a.name)
                else:
                    atom = Atom(atomic_number=a.element.atomic_number,
                                name=a.name,
                                mass=a.element.mass)
                struct.add_atom(atom, residue, resid, chain)
                atommap[a] = atom
    for a1, a2 in topology.bonds():
        struct.bonds.append(Bond(atommap[a1], atommap[a2]))

    vectors = topology.getPeriodicBoxVectors()
    if vectors is not None:
        leng, ang = box_vectors_to_lengths_and_angles(*vectors)
        leng = leng.value_in_unit(u.angstroms)
        ang = ang.value_in_unit(u.degrees)
        struct.box = [leng[0], leng[1], leng[2], ang[0], ang[1], ang[2]]

    loaded_box = False

    if xyz is not None:
        if isinstance(xyz, string_types):
            xyz = load_file(xyz, skip_bonds=True)
            struct.coordinates = xyz.coordinates
            if struct.box is not None:
                if xyz.box is not None:
                    loaded_box = True
                    struct.box = xyz.box
        else:
            struct.coordinates = xyz

    if box is not None:
        loaded_box = True
        struct.box = box

    if struct.box is not None:
        struct.box = np.asarray(struct.box)

    if system is None:
        return struct

    if isinstance(system, string_types):
        system = load_file(system)

    if not isinstance(system, mm.System):
        raise TypeError('system must be an OpenMM System object or serialized '
                        'XML of an OpenMM System object')

    # We have a system, try to extract parameters from it
    if len(struct.atoms) != system.getNumParticles():
        raise TypeError('Topology and System have different numbers of atoms '
                        '(%d vs. %d)' %
                        (len(struct.atoms), system.getNumParticles()))

    processed_forces = set()
    ignored_forces = (mm.CMMotionRemover, mm.AndersenThermostat,
                      mm.MonteCarloBarostat, mm.MonteCarloAnisotropicBarostat,
                      mm.MonteCarloMembraneBarostat, mm.CustomExternalForce,
                      mm.GBSAOBCForce, mm.CustomGBForce)

    if system.usesPeriodicBoundaryConditions():
        if not loaded_box:
            vectors = system.getDefaultPeriodicBoxVectors()
            leng, ang = box_vectors_to_lengths_and_angles(*vectors)
            leng = leng.value_in_unit(u.angstroms)
            ang = ang.value_in_unit(u.degrees)
            struct.box = np.asarray(
                [leng[0], leng[1], leng[2], ang[0], ang[1], ang[2]])
    else:
        struct.box = None

    for force in system.getForces():
        if isinstance(force, mm.HarmonicBondForce):
            if mm.HarmonicBondForce in processed_forces:
                # Try to process this HarmonicBondForce as a Urey-Bradley term
                _process_urey_bradley(struct, force)
            else:
                _process_bond(struct, force)
        elif isinstance(force, mm.HarmonicAngleForce):
            _process_angle(struct, force)
        elif isinstance(force, mm.PeriodicTorsionForce):
            _process_dihedral(struct, force)
        elif isinstance(force, mm.RBTorsionForce):
            _process_rbtorsion(struct, force)
        elif isinstance(force, mm.CustomTorsionForce):
            if not _process_improper(struct, force):
                struct.unknown_functional = True
                warnings.warn('Unknown functional form of CustomTorsionForce',
                              OpenMMWarning)
        elif isinstance(force, mm.CMAPTorsionForce):
            _process_cmap(struct, force)
        elif isinstance(force, mm.NonbondedForce):
            _process_nonbonded(struct, force)
        elif isinstance(force, ignored_forces):
            continue
        else:
            struct.unknown_functional = True
            warnings.warn('Unsupported Force type %s' % type(force).__name__,
                          OpenMMWarning)
        processed_forces.add(type(force))

    return struct