Пример #1
0
def get_topology_from_pdbfile(filename):
    """
    Reads the positions from a PDB file.

    :param filename: Path to the file where we will read PDB coordinates.
    :type filename: str

    :returns:
      - topology ( `Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ ) - OpenMM Topology() object, which stores bonds, angles, and other structural attributes of the coarse grained model
    """
    pdb_mm_obj = PDBFile(filename)
    topology = pdb_mm_obj.getTopology()

    return topology
Пример #2
0
def read_pdbfile(cgmodel, filename):
    """
    Reads the positions and topology from a PDB file.

    :param cgmodel: CGModel() class object
    :type cgmodel: class

    :param filename: Path to the file where we will read PDB coordinates.
    :type filename: str

    :returns:
      - cgmodel - A CGModel() class object with the positions and topology from the PDB file that was read.

    """

    pdb_mm_obj = PDBFile(filename)
    cgmodel.positions = pdb_mm_obj.getPositions()
    cgmodel.topology = pdb_mm_obj.getTopology()

    return cgmodel
Пример #3
0
def build_topology(cgmodel, use_pdbfile=False, pdbfile=None):
    """

    Construct an OpenMM `Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ class object for our coarse grained model,

    :param cgmodel: CGModel() class object
    :type cgmodel: class

    :param use_pdbfile: Determines whether or not to use a PDB file in order to generate the Topology().
    :type use_pdbfile: Logical

    :param pdbfile: Name of a PDB file to use when building the topology.
    :type pdbfile: str

    :returns:
        - topology (`Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ ) - OpenMM Topology() object

    :Example:

    >>> from foldamers.cg_model.cgmodel import CGModel
    >>> from foldamers.util.iotools import write_pdbfile_without_topology
    >>> input_pdb = "top.pdb"
    >>> cgmodel = CGModel()
    >>> write_pdbfile_without_topology(cgmodel,input_pdb)
    >>> topology = build_topology(cgmodel,use_pdbfile=True,pdbfile=input_pdb)
    >>> cgmodel.topology = topology

    .. warning:: When 'use_pdbfile'=True, this function will use the `PDBFile() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1pdbfile_1_1PDBFile.html>`_ class object from OpenMM to build the Topology().  In order for this approach to function correctly, the particle names in the PDB file must match the particle names in the coarse grained model.

    """
    if cgmodel.constrain_bonds:
        use_pdbfile = True

    if use_pdbfile:
        if pdbfile is None:
            tf = tempfile.NamedTemporaryFile()
            write_pdbfile_without_topology(cgmodel, tf.name)
            pdb = PDBFile(tf.name)
            topology = pdb.getTopology()
            tf.close()
            return topology
        else:
            pdb = PDBFile(pdbfile)
            topology = pdb.getTopology()
            return topology

    topology = Topology()

    chain = topology.addChain()
    residue_index = -1
    openmm_particle_list = list()
    for particle in cgmodel.particle_list:
        if particle["monomer"] > residue_index:
            residue_index = particle["monomer"]
            residue = topology.addResidue(str(residue_index), chain)
        particle_symbol = particle["name"]
        element = elem.Element.getBySymbol(particle_symbol)
        openmm_particle = topology.addAtom(particle_symbol, element, residue)
        openmm_particle_list.append(particle)

    if cgmodel.include_bond_forces or cgmodel.constrain_bonds:
        for bond in cgmodel.bond_list:
            topology.addBond(openmm_particle_list[bond[0]],
                             openmm_particle_list[bond[1]])

    cgmodel.topology = topology
    verify_topology(cgmodel)
    return topology
Пример #4
0
def build_topology(cgmodel, use_pdbfile=False, pdbfile=None):
    """

        Construct an OpenMM `Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ class object for our coarse grained model,

        :param cgmodel: CGModel() class object
        :type cgmodel: class

        :param use_pdbfile: Determines whether or not to use a PDB file in order to generate the Topology().
        :type use_pdbfile: Logical

        :param pdbfile: Name of a PDB file to use when building the topology.
        :type pdbfile: str

        :returns:
            - topology (`Topology() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1topology_1_1Topology.html>`_ ) - OpenMM Topology() object

        :Example:

        >>> from foldamers.cg_model.cgmodel import CGModel
        >>> from foldamers.util.iotools import write_pdbfile_without_topology
        >>> input_pdb = "top.pdb"
        >>> cgmodel = CGModel()
        >>> write_pdbfile_without_topology(cgmodel,input_pdb)
        >>> topology = build_topology(cgmodel,use_pdbfile=True,pdbfile=input_pdb)
        >>> cgmodel.topology = topology

        .. warning:: When 'use_pdbfile'=True, this function will use the `PDBFile() <https://simtk.org/api_docs/openmm/api4_1/python/classsimtk_1_1openmm_1_1app_1_1pdbfile_1_1PDBFile.html>`_ class object from OpenMM to build the Topology().  In order for this approach to function correctly, the particle names in the PDB file must match the particle names in the coarse grained model.

        """
    if use_pdbfile == True:
        if pdbfile == None:
            write_pdbfile_without_topology(cgmodel, "topology_source.pdb")
            pdb = PDBFile("topology_source.pdb")
            topology = pdb.getTopology()
            os.remove("topology_source.pdb")
            return (topology)
        else:
            pdb = PDBFile(pdbfile)
            topology = pdb.getTopology()
            return (topology)

    topology = Topology()

    chain = topology.addChain()
    residue_index = 1
    cg_particle_index = 0
    for monomer_type in cgmodel.sequence:
        residue = topology.addResidue(str(residue_index), chain)
        for backbone_bead in range(monomer_type['backbone_length']):
            particle_symbol = cgmodel.get_particle_name(cg_particle_index)
            element = elem.Element.getBySymbol(particle_symbol)
            particle = topology.addAtom(particle_symbol, element, residue)
            if backbone_bead == 0 and residue_index != 1:
                topology.addBond(particle, last_backbone_particle)
            last_backbone_particle = particle
            cg_particle_index = cg_particle_index + 1
            if backbone_bead in [monomer_type['sidechain_positions']]:
                for sidechain_bead in range(monomer_type['sidechain_length']):
                    particle_symbol = cgmodel.get_particle_name(
                        cg_particle_index)
                    element = elem.Element.getBySymbol(particle_symbol)
                    particle = topology.addAtom(particle_symbol, element,
                                                residue)
                    if sidechain_bead == 0:
                        topology.addBond(particle, last_backbone_particle)
                    if sidechain_bead != 0:
                        topology.addBond(particle, last_sidechain_particle)
                    last_sidechain_particle = particle
                    cg_particle_index = cg_particle_index + 1
        residue_index = residue_index + 1
    cgmodel.topology = topology
    verify_topology(cgmodel)
    return (topology)