Beispiel #1
0
def getRMSD(traj, nativePDB, resname, symmetries, topology=None):
    """
        Computes the RMSD of a trajectory, given a native and symmetries

        :param traj: Trajecotry filename
        :type traj: str
        :param nativePDB:  Native PDB object
        :type native PDB: :py:class:`.PDB`
        :param resname: Resname to compute its RMSD
        :type resname: str
        :param symmetries: Symmetries dictionary list with independent symmetry groups
        :type symmetries: list of dict
        :param topology: Topology for non-pdb trajectories
        :type topology: list

        :return: np.array -- Array with the rmsd values of the trajectory
    """

    snapshots = getSnapshots(traj)
    rmsds = np.zeros(len(snapshots))
    RMSDCalc = RMSDCalculator.RMSDCalculator(symmetries)
    for i, snapshot in enumerate(snapshots):
        snapshotPDB = atomset.PDB()
        snapshotPDB.initialise(snapshot, resname=resname, topology=topology)

        rmsds[i] = RMSDCalc.computeRMSD(nativePDB, snapshotPDB)

    return rmsds
Beispiel #2
0
    def testPDB_RMSD(self):
        # preparation
        pdb_native = atomset.PDB()
        pdb_native.initialise("tests/data/ain_native_fixed.pdb", resname='AIN')
        pdb_traj = atomset.PDB()
        pdb_traj.initialise("tests/data/ain_trajectory.pdb", resname='AIN')
        RMSDCalc = RMSDCalculator.RMSDCalculator()

        # function to test
        RMSD = RMSDCalc.computeRMSD(pdb_native, pdb_traj)
        golden_RMSD = 3.928617
        self.assertAlmostEqual(RMSD, golden_RMSD, 5)
Beispiel #3
0
def main(lig_resname, native_path, initial_path, up_lim, low_lim, filename):
    RMSDCalc = RMSDCalculator.RMSDCalculator()
    nativePDB = atomset.PDB()
    nativePDB.initialise(native_path, resname=lig_resname)
    filtered = []
    for conf in glob.glob(
            os.path.join(initial_path, "{}*.pdb".format(filename))):
        initialPDB = atomset.PDB()
        initialPDB.initialise(conf, resname=lig_resname)
        if low_lim < RMSDCalc.computeRMSD(nativePDB, initialPDB) < up_lim:
            filtered.append(conf)
    print(" ".join(filtered))
Beispiel #4
0
 def testPDB_RMSD_symmetries(self):
     # preparation
     pdb_native = atomset.PDB()
     pdb_native.initialise("tests/data/ain_native_fixed.pdb", resname='AIN')
     pdb_traj = atomset.PDB()
     pdb_traj.initialise("tests/data/ain_trajectory.pdb", resname='AIN')
     symDict = [{"1733:O1:AIN": "1735:O2:AIN"}]
     RMSDCalc = RMSDCalculator.RMSDCalculator(symDict)
     # function to test
     RMSD = RMSDCalc.computeRMSD(pdb_native, pdb_traj)
     reverseRMSD = RMSDCalc.computeRMSD(pdb_traj, pdb_native)
     golden_RMSD = 3.860743
     self.assertAlmostEqual(RMSD, reverseRMSD, 5)
     self.assertAlmostEqual(RMSD, golden_RMSD, 5)
Beispiel #5
0
def main(resname, files_glob, native):
    input_files = glob.glob(files_glob)
    nativePDB = atomset.PDB()
    nativePDB.initialise(native, resname=resname)
    RMSDCalc = RMSDCalculator.RMSDCalculator()
    results = {}
    for f in input_files:
        p = atomset.PDB()
        p.initialise(f, resname=resname)
        results[f] = RMSDCalc.computeRMSD(nativePDB, p)
    with open("rmsd_file.dat", "w") as fw:
        fw.write("File\tRMSD(A)\n")
        for f in results:
            fw.write("%s\t%.4f\n" % (f, results[f]))
Beispiel #6
0
 def __init__(self,
              thresholdCalculator,
              resname=None,
              reportBaseFilename=None,
              columnOfReportFile=None,
              contactThresholdDistance=8,
              symmetries=[]):
     clustering.Clustering.__init__(self, resname, reportBaseFilename,
                                    columnOfReportFile,
                                    contactThresholdDistance)
     self.type = clusteringTypes.CLUSTERING_TYPES.contacts
     self.thresholdCalculator = thresholdCalculator
     self.symmetries = symmetries
     self.initialPDB = None
     self.maxThreshold = self.thresholdCalculator.getMaxThreshold()
     self.distancesList = []
     self.RMSDCalculator = RMSDCalculator.RMSDCalculator(symmetries)
Beispiel #7
0
 def testPDB_RMSD_symmetries_XTC(self):
     # preparation
     golden = "tests/data/ain_native_fixed.pdb"
     topology = utilities.getTopologyFile(golden)
     xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
     xtc = atomset.PDB()
     xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
     golden_pdb = atomset.PDB()
     golden_pdb.initialise(golden, resname="AIN")
     symDict = [{"1733:O1:AIN": "1735:O2:AIN"}]
     RMSDCalc = RMSDCalculator.RMSDCalculator(symDict)
     # function to test
     RMSD = RMSDCalc.computeRMSD(xtc, golden_pdb)
     reverseRMSD = RMSDCalc.computeRMSD(golden_pdb, xtc)
     golden_RMSD = 0.00000
     self.assertAlmostEqual(RMSD, reverseRMSD, 2)
     self.assertAlmostEqual(RMSD, golden_RMSD, 2)
Beispiel #8
0
    def testPDB_RMSD_XTC(self):
        # preparation
        golden = "tests/data/ain_native_fixed.pdb"
        topology = utilities.getTopologyFile(golden)
        xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
        xtc = atomset.PDB()
        xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
        golden_pdb = atomset.PDB()
        golden_pdb.initialise(golden, resname="AIN")

        # assertion
        RMSDCalc = RMSDCalculator.RMSDCalculator()

        # function to test
        RMSD = RMSDCalc.computeRMSD(golden_pdb, xtc)
        golden_RMSD = 0.0000
        self.assertAlmostEqual(RMSD, golden_RMSD, 2)
Beispiel #9
0
def main(args):

    # Parameters
    clusteringObj = utilities.readClusteringObject(args.clusteringObj)
    native = args.native
    pathwayFilename = args.pathwayFilename
    ntrajs = args.ntrajs
    threshold = args.threshold
    RMSDCalc = RMSDCalculator.RMSDCalculator(clusteringObj.symmetries)

    # use graph algorithm to establish a path
    initial_cluster = 0
    final_cluster = getOptimalCluster(clusteringObj, native, RMSDCalc)
    distanceMatrix = createNetworkMatrix(clusteringObj, threshold, RMSDCalc)
    predecessors = obtainShortestPath(distanceMatrix)
    pathway = createPathway(initial_cluster, final_cluster, predecessors)
    print "Pathway clusters:"
    print pathway

    # write pathway into a single trajectory
    writePathwayTrajectory(clusteringObj, pathway, pathwayFilename, native)

    # create clustering object with only the pathway clusters
    ClPath = clustering.Clustering()
    ClPath.clusters.clusters = map(
        lambda x: clusteringObj.clusters.clusters[x], pathway)

    # spawning along the trajectory
    spawningParams = spawning.SpawningParams()
    densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder()
    densityCalculator = densityCalculatorBuilder.build({})
    spawningPathway = spawning.InverselyProportionalToPopulationCalculator(
        densityCalculator)
    # Set a least 1 processors from the extrems of the path
    degeneracies = spawningPathway.calculate(ClPath.clusters.clusters,
                                             ntrajs - 2, spawningParams)
    degeneracies[0] += 1
    degeneracies[-1] += 1
    print "degeneracies over pathway:"
    print degeneracies
    print ""
def main(epoch_num, trajectory, snapshot_num, resname, clustering_object, topology):
    calc = RMSDCalculator.RMSDCalculator()
    clustering_object = utilities.readClusteringObject(clustering_object)
    n_clusters = np.loadtxt(os.path.join(str(epoch_num-1), "clustering", "summary.txt")).shape[0]
    if topology is not None:
        topology_contents = utilities.getTopologyFile(topology)
    else:
        topology_contents = None
    filename = glob.glob(os.path.join(str(epoch_num), "*traj*_%d.*" % trajectory))
    if not filename:
        raise ValueError("No file with the specified epoch and trajectory found")
    try:
        snapshots = utilities.getSnapshots(filename[0], topology=topology)[snapshot_num]
    except IndexError:
        raise IndexError("Snapshot number %d not found in trajectory %d for epoch %d, please check that the arguments provided are correct" % (snapshot_num, trajectory, epoch_num))
    pdb = atomset.PDB()
    pdb.initialise(snapshots, resname=resname)
    for i, cluster in enumerate(clustering_object[:n_clusters]):
        dist = calc.computeRMSD(pdb, cluster.pdb)
        if dist < cluster.threshold:
            print("Snapshot belongs to cluster", i)
            return
    print("Snapshot not assigned to any cluster! :(")
Beispiel #11
0
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import range
import networkx as nx
from AdaptivePELE.utilities import utilities
from AdaptivePELE.atomset import RMSDCalculator


def weight(pathway, confs):
    w = 0
    for j in range(1, len(path)):
        w += confs[pathway[j - 1]][path[j]]['metric']
    return w


metricCol = 4
RMSDCalc = RMSDCalculator.RMSDCalculator()
cl = utilities.readClusteringObject("ClCont.pkl")
nodeFin = cl.getOptimalMetric(column=metricCol)
conf = nx.DiGraph()
nx.read_edgelist("conformationNetwork_4DAJ.edgelist",
                 create_using=conf,
                 data=True,
                 nodetype=int)
for source, target in conf.edges_iter():
    clusterSource = cl.getCluster(source)
    clusterTarget = cl.getCluster(target)
    conf[source][target]['metric'] = RMSDCalc.computeRMSD(
        clusterSource.pdb, clusterTarget.pdb)

# paths = nx.all_simple_paths(conf, 0, nodeFin)
paths = nx.shortest_simple_paths(conf, 0, nodeFin, weight='metric')