Пример #1
0
def process_folder(epoch,
                   folder,
                   trajName,
                   reportName,
                   output_filename,
                   top,
                   trajs_to_select=None):
    if epoch is None:
        allTrajs = glob.glob(os.path.join(folder, trajName))
        full_reportName = os.path.join(folder, reportName)
    else:
        allTrajs = glob.glob(os.path.join(folder, epoch, trajName))
        full_reportName = os.path.join(folder, epoch, reportName)
        epoch = int(epoch)

    allFiles = []
    for traj in allTrajs:
        trajNum = utilities.getTrajNum(traj)
        if trajs_to_select is not None and trajNum not in trajs_to_select:
            continue
        if top is not None:
            top_file = top.getTopologyFile(epoch, trajNum)
        else:
            top_file = None
        report_file = full_reportName % trajNum
        allFiles.append(
            (traj, report_file, top_file, epoch, output_filename % trajNum))
    return allFiles
Пример #2
0
def trajectory_and_snapshot_to_pdb(trajectory_path, snapshot, output_path,
                                   topology_contents):
    """
    Given an absolute path to a trajectory of Adaptive and a snapshot (MODEL) in xtc format, the function transform it
    into a PDB format.
    :param trajectory_path: Absolute path to a trajectory from Adaptive, in xtc format.
    :type trajectory_path:str
    :param snapshot: model of a trajectory that you want to transform.
    :type snapshot: int
    :param output_path: output path of the new pdb file.
    :type output_path: str
    :return: Creates a PDB file.
    """
    # get the path where the adaptive simulation resides
    topology_path_splited = trajectory_path.split(os.sep)
    epoch = int(topology_path_splited[-2])
    traj = adapt_tools.getTrajNum(topology_path_splited[-1])
    trajectory = adapt_tools.getSnapshots(trajectory_path)
    try:
        single_model = trajectory[snapshot]
        PDB = atomset.PDB()
        PDB.initialise(single_model,
                       topology=topology_contents.getTopology(epoch, traj))
    except IndexError:
        exit(
            "You are selecting the model {} for a trajectory that has {} models, please, reselect the model index "
            "(starting from 0).".format(snapshot, len(trajectory)))
    with open(output_path, "w") as fw:
        fw.write("MODEL     %4d\n" % (snapshot + 1))
        fw.write(PDB.pdb)
        fw.write("ENDMDL\n")
        fw.write("END\n")
def fixReportsSymmetry(outputPath, resname, reschain, resnum, nativeStructure,
                       symmetries, topologies):
    """
        Adds a new column in the report file with the RMSD that takes into account symmetries.
        New reports are stored in the fixedReport_i where i is the number of the report

        :param outputPath: Path where trajectories are found
        :type outputPath: str
        :param resname: Residue name of the ligand in the system pdb
        :type resname: str
        :param reschain: Chain name of the ligand in the system pdb
        :type reschain: str
        :param resnum: Residue number of the ligand in the system pdb
        :type resnum: int
        :param nativeStructure: Path to the native structure pdb
        :type nativeStructure: str
        :param symmetries: Dictionary containg the symmetries of the ligand
        :type symmetries: dict
        :param topologies: Topology object containing the set of topologies needed for the simulation
        :type topologies: :py:class:`.Topology`

        :raise IndexError: If original report file not found in output folder
    """
    outputFilename = "fixedReport_%d"  # move to constants?
    trajName = "*traj*"  # move to constants?
    reportName = "*report_%d"  # move to constants?
    epoch = int(os.path.basename(outputPath))
    trajs = glob.glob(os.path.join(outputPath, trajName))
    nativePDB = atomset.PDB()
    nativePDB.initialise(str(nativeStructure),
                         resname=resname,
                         chain=reschain,
                         resnum=resnum)
    for traj in trajs:
        trajNum = utilities.getTrajNum(traj)
        rmsd = list(
            utilities.getRMSD(traj,
                              nativePDB,
                              resname,
                              reschain,
                              resnum,
                              symmetries,
                              topology=topologies.getTopology(epoch, trajNum)))
        try:
            reportFilename = glob.glob(
                os.path.join(outputPath, reportName) % trajNum)[0]
        except IndexError:
            raise IndexError("File %s not found in folder %s" %
                             (reportName % trajNum, outputPath))
        rmsd.insert(0, "\tCorrected RMSD")
        with open(reportFilename, "r") as f:
            report = f.readlines()
        outfile = open(os.path.join(outputPath, outputFilename % trajNum), "w")
        for line, value in zip(report, rmsd):
            outfile.write(line.rstrip("\n") + str(value) + "\n")
        outfile.close()
Пример #4
0
def main(controlFile):
    """
        Calculate the corrected rmsd values of conformation taking into account
        molecule symmetries

        :param controlFile: Control file
        :type controlFile: str
    """
    # Constants
    folder = "."
    outputFilename = "fixedReport_%d"
    trajName = "*traj*"
    reportName = "*report_%d"
    # end constants

    resname, nativeFilename, symmetries, rmsdColInReport = readControlFile(
        controlFile)

    nativePDB = atomset.PDB()
    nativePDB.initialise(nativeFilename, resname=resname)

    allFolders = os.listdir(folder)
    epochs = [epoch for epoch in allFolders if epoch.isdigit()]

    for epoch in epochs:
        print("Epoch", epoch)
        os.chdir(epoch)
        allTrajs = glob.glob(trajName)

        for traj in allTrajs:
            rmsds = utilities.getRMSD(traj, nativePDB, resname, symmetries)
            trajNum = utilities.getTrajNum(traj)
            try:
                reportFilename = glob.glob(reportName % trajNum)[0]
            except IndexError:
                raise IndexError("File %s not found in folder %s" %
                                 (reportName % trajNum, epoch))

            reportFile = np.loadtxt(reportFilename, ndmin=2)

            if rmsdColInReport > 0 and rmsdColInReport < reportFile.shape[1]:
                reportFile[:, rmsdColInReport] = rmsds
                fixedReport = reportFile
            else:
                fixedReport = extendReportWithRmsd(reportFile, rmsds)

            # print(fixedReport)
            np.savetxt(outputFilename % trajNum, fixedReport, fmt=b'%.4f')

        os.chdir("..")
def main(trajectory_name, path, n_processors, imaging):
    epochs = utilities.get_epoch_folders(path)
    to_process = []
    pool = mp.Pool(n_processors)
    trajectory_glob = trajectory_name + "_*"
    for epoch in epochs:
        with open(os.path.join(epoch, "topologyMapping.txt")) as f:
            top_map = f.read().rstrip().split(":")
        for traj in glob.glob(os.path.join(path, epoch, trajectory_glob)):
            traj_num = utilities.getTrajNum(traj)
            to_process.append(
                (top_map[traj_num - 1], traj, epoch, traj_num, imaging))

    pool.map(process_traj, to_process)
    pool.close()
    pool.terminate()
Пример #6
0
def get_epoch_traj_num(filename):
    # assumes trajectories come from an Adaptive simulation
    path, traj_name = os.path.split(filename)
    try:
        epoch = int(os.path.split(path)[-1])
    except ValueError:
        # if for some reason epoch number can't be inferred, assume first
        # epoch
        epoch = 0
    try:
        traj_num = utilities.getTrajNum(traj_name)
    except ValueError:
        # if for some reason trajectory number can't be inferred, assume
        # first trajectory
        traj_num = 1
    return epoch, traj_num
Пример #7
0
def mapReference(ref, trajs, topology_content):
    refPDB = atomset.PDB()
    refPDB.initialise(ref, type="PROTEIN", topology=topology_content)
    avgStruct = {
        atomID: refPDB.atoms[atomID].getAtomCoords()
        for atomID in refPDB.atoms
    }
    snapshotsTot = []
    for traj in trajs:
        snapshots = utilities.getSnapshots(traj)
        traj_num = utilities.getTrajNum(traj)
        epoch = int(os.path.abspath(traj).split(os.sep)[-2])
        snapshots = utilities.getSnapshots(traj)
        for snapshot in snapshots:
            PDB = atomset.PDB()
            PDB.initialise(snapshot,
                           type="PROTEIN",
                           topology=topology_content.getTopology(
                               epoch, traj_num))
            snapshotsTot.append(PDB)

    return avgStruct, snapshotsTot
Пример #8
0
def extractAvgPDB(trajs, topology_content):
    nSnapshots = 0
    avgStruct = {}
    snapshotsTot = []
    for traj in trajs:
        snapshots = utilities.getSnapshots(traj)
        traj_num = utilities.getTrajNum(traj)
        epoch = int(os.path.abspath(traj).split(os.sep)[-2])
        for snapshot in snapshots:
            nSnapshots += 1
            PDB = atomset.PDB()
            PDB.initialise(snapshot,
                           type="PROTEIN",
                           topology=topology_content.getTopology(
                               epoch, traj_num))
            snapshotsTot.append(PDB)
            for atomID, atom in PDB.atoms.items():
                if atomID in avgStruct:
                    avgStruct[atomID] += (atom.getAtomCoords() -
                                          avgStruct[atomID]) / nSnapshots
                else:
                    avgStruct[atomID] = atom.getAtomCoords()
    return avgStruct, snapshotsTot