예제 #1
0
def writeFilenameExtractedCoordinates(filename,
                                      params,
                                      pathFolder,
                                      constants,
                                      topology,
                                      indexes=None):
    """
        Process the coordinates of a trajectory

    """
    if params.dihedrals:
        coords = calculateDihedrals(filename, params, topology)
        if params.dihedrals_projection:
            coords = projectDihedrals(coords)
        outputFilename = getOutputFilename(
            constants.extractedTrajectoryFolder, filename,
            constants.baseExtractedTrajectoryName)
        writeToFile(coords, outputFilename % pathFolder)
        return
    ext = utilities.getFileExtension(filename)
    if ext == ".pdb":
        allCoordinates = loadAllResnameAtomsInPdb(filename, params)
        if params.writeLigandTrajectory:
            outputFilename = os.path.join(
                pathFolder, constants.ligandTrajectoryBasename %
                extractFilenumber(filename))
            with open(outputFilename, 'w') as f:
                f.write("\nENDMDL\n".join(allCoordinates))
        if params.protein_CA:
            coords = getLigandAlphaCarbonsCoords(allCoordinates,
                                                 params.lig_resname)
        elif params.sidechains:
            coords = getLigandAlphaCarbonsCoords(allCoordinates,
                                                 params.lig_resname,
                                                 sidechains=params.sidechains)
        else:
            if params.com:
                coords = getPDBCOM(allCoordinates, params.lig_resname)
            elif params.contact_map:
                coords = np.array(
                    extractContactMapCoordinatesPDB(allCoordinates, params))
                coords = utils.contactMap(coords, int(coords.shape[1] / 3))
            else:
                coords = getAtomCoord(allCoordinates, params.lig_resname,
                                      params.atomIds)
    elif ext in MDTRAJ_FORMATS:
        if not indexes:
            raise ValueError("Empty selection!!!")
        if params.contact_map:
            coords = contactMapNonPDB(filename, params, topology, indexes)
        else:
            coords = extractCoordinatesXTCFile(filename, params, topology,
                                               indexes)
    else:
        raise ValueError("Unrecongnized file extension for %s" % filename)

    outputFilename = getOutputFilename(constants.extractedTrajectoryFolder,
                                       filename,
                                       constants.baseExtractedTrajectoryName)
    writeToFile(coords, outputFilename % pathFolder)
예제 #2
0
def getTopologyObject(topology_file):
    ext = utilities.getFileExtension(topology_file)
    if ext == ".pdb":
        return TopologyCompat(topology_file)
    elif ext == ".pkl":
        return utilities.readClusteringObject(topology_file)
    else:
        raise ValueError(
            "The topology parameter needs to be the path to a pickled Topology object or a pdb!"
        )
예제 #3
0
def extractSidechainIndexes(params, pool=None):
    trajs = glob.glob(params.sidechain_folder)
    sidechains_trajs = []
    workers = []
    for traj in trajs:
        ext = utilities.getFileExtension(traj)

        if ext == ".pdb":
            if PRODY:
                if pool is None:
                    sidechains_trajs.extend(
                        extractSidechainIndexes_prody(traj,
                                                      params.lig_resname))
                else:
                    workers.append(
                        pool.apply_async(extractSidechainIndexes_prody,
                                         args=(traj, params.lig_resname)))
            else:
                if pool is None:
                    sidechains_trajs.extend(
                        extractSidechainIndexes_mdtraj(traj,
                                                       params.lig_resname))
                else:
                    workers.append(
                        pool.apply_async(extractSidechainIndexes_mdtraj,
                                         args=(traj, params.lig_resname)))
        elif ext in MDTRAJ_FORMATS:
            epoch, traj_num = get_epoch_traj_num(traj)
            if pool is None:
                sidechains_trajs.extend(
                    extractSidechainIndexes_mdtraj(
                        traj,
                        params.lig_resname,
                        topology=params.topology.getTopologyFile(
                            epoch, traj_num)))
            else:
                workers.append(
                    pool.apply_async(
                        extractSidechainIndexes_mdtraj(traj,
                                                       params.lig_resname,
                                                       params.topology)))
        else:
            raise ValueError("Unrecongnized file extension for %s" % traj)
    for w in workers:
        sidechains_trajs.extend(w.get())
    return list(set(sidechains_trajs))
예제 #4
0
def writeFilenameExtractedCoordinates(filename,
                                      lig_resname,
                                      atom_Ids,
                                      pathFolder,
                                      writeLigandTrajectory,
                                      constants,
                                      writeCA,
                                      sidechains,
                                      topology=None,
                                      indexes=None):
    """
        Process the coordinates of a trajectory

    """
    ext = utilities.getFileExtension(filename)
    if ext == ".pdb":
        allCoordinates = loadAllResnameAtomsInPdb(filename, lig_resname,
                                                  writeCA, sidechains)
        if writeLigandTrajectory:
            outputFilename = os.path.join(
                pathFolder, constants.ligandTrajectoryBasename %
                extractFilenumber(filename))
            with open(outputFilename, 'w') as f:
                f.write("\nENDMDL\n".join(allCoordinates))
        if writeCA:
            coords = getLigandAlphaCarbonsCoords(allCoordinates, lig_resname)
        elif sidechains:
            coords = getLigandAlphaCarbonsCoords(allCoordinates,
                                                 lig_resname,
                                                 sidechains=sidechains)
        else:
            if atom_Ids is None or len(atom_Ids) == 0:
                coords = getPDBCOM(allCoordinates, lig_resname)
            else:
                coords = getAtomCoord(allCoordinates, lig_resname, atom_Ids)
    elif ext in MDTRAJ_FORMATS:
        coords = extractCoordinatesXTCFile(filename, lig_resname, atom_Ids,
                                           writeCA, topology, indexes,
                                           sidechains)
    else:
        raise ValueError("Unrecongnized file extension for %s" % filename)

    outputFilename = getOutputFilename(constants.extractedTrajectoryFolder,
                                       filename,
                                       constants.baseExtractedTrajectoryName)
    writeToFile(coords, outputFilename % pathFolder)