Пример #1
0
def get_minimum_energy_ensemble(topology,replica_energies,replica_positions,ensemble_size=5,file_name=None):
        """
        Get an ensemble of low (potential) energy poses, and write the lowest energy structure to a PDB file if a file_name is provided.

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

        :param replica_energies: List of dimension num_replicas X simulation_steps, which gives the energies for all replicas at all simulation steps 
        :type replica_energies: List( List( float * simtk.unit.energy for simulation_steps ) for num_replicas )

        :param replica_positions: List of positions for all output frames for all replicas
        :type replica_positions: np.array( ( float * simtk.unit.positions for num_beads ) for simulation_steps )

        :param file_name: Output destination for PDB coordinates of minimum energy pose, Default = None

        :returns:
             - ensemble ( List() ) - A list of poses that are in the minimum energy ensemble.

        :Example:

        >>> from foldamers.cg_model.cgmodel import CGModel
        >>> from cg_openmm.simulation.rep_exch import *
        >>> cgmodel = CGModel()
        >>> replica_energies,replica_positions,replica_state_indices = run_replica_exchange(cgmodel.topology,cgmodel.system,cgmodel.positions)
        >>> ensemble_size = 5
        >>> file_name = "minimum.pdb"
        >>> minimum_energy_ensemble = get_minimum_energy_ensemble(cgmodel.topology,replica_energies,replica_positions,ensemble_size=ensemble_size,file_name=file_name)

        """
        # Get the minimum energy structure sampled during the simulation
        ensemble = []
        ensemble_energies = []
        for replica in range(len(replica_energies)):
          energies = np.array([energy for energy in replica_energies[replica][replica]])
          for energy in range(len(energies)):
            if len(ensemble) < ensemble_size:
              ensemble.append(replica_positions[replica][energy])
              ensemble_energies.append(energies[energy])
            else:

             for comparison in range(len(ensemble_energies)):
              if energies[energy] < ensemble_energies[comparison]:
               ensemble_energies[comparison] = energies[energy]
               ensemble[comparison] = replica_positions[replica][energy]

        if file_name == None:
         index = 1
         for pose in ensemble:
          file = open(str("re_min_"+str(index)+".pdb"),"w")
          PDBFile.writeFile(topology,pose,file=file)
        else:
          file = open(file_name,"w")
          for pose in ensemble:
            PDBFile.writeFile(topology,pose,file=file)

        return(ensemble)
Пример #2
0
def write_single_pdb(xp, top, target):
    """Dump coordinates to a pdb file `target`."""
    try:
        target = Path(target)
    except TypeError:
        if hasattr(target, 'write'):
            PDBFile.writeFile(top, xp, target)
        else:
            raise
    else:
        with open(target, 'w') as fp:
            PDBFile.writeFile(top, xp, fp)
Пример #3
0
def fix_pdb(pdb_id):
    path = os.getcwd()
    if len(pdb_id) != 4:
        print("Creating PDBFixer...")
        fixer = PDBFixer(pdb_id)
        print("Finding missing residues...")
        fixer.findMissingResidues()

        chains = list(fixer.topology.chains())
        keys = fixer.missingResidues.keys()
        for key in list(keys):
            chain = chains[key[0]]
            if key[1] == 0 or key[1] == len(list(chain.residues())):
                print("ok")
                del fixer.missingResidues[key]

        print("Finding nonstandard residues...")
        fixer.findNonstandardResidues()
        print("Replacing nonstandard residues...")
        fixer.replaceNonstandardResidues()
        print("Removing heterogens...")
        fixer.removeHeterogens(keepWater=True)

        print("Finding missing atoms...")
        fixer.findMissingAtoms()
        print("Adding missing atoms...")
        fixer.addMissingAtoms()
        print("Adding missing hydrogens...")
        fixer.addMissingHydrogens(7)
        print("Writing PDB file...")

        PDBFile.writeFile(
            fixer.topology,
            fixer.positions,
            open(
                os.path.join(path,
                             "%s_fixed_pH_%s.pdb" % (pdb_id.split('.')[0], 7)),
                "w"),
            keepIds=True)
        return "%s_fixed_pH_%s.pdb" % (pdb_id.split('.')[0], 7)