Beispiel #1
0
     def generatePDB(frame):
         """Generate the PDB for a certain frame"""
         with open("frame_%i.in" % frame, 'w') as script:
             script.write("""parm %s
 trajin %s %i %i 1
 trajout frame_%i.pdb pdb
 """ % (PRMTOPPATH, COORDPATH, frame, frame, frame))
         system("cpptraj < frame_%i.in > /dev/null 2> /dev/null" % frame)
         with open("frame_%i.pdb" % frame) as pdb:
             thisDist = rmsdDist(pdbLines=list(pdb), refCoords=REFCOORDS, segments=SEGMENTS)
             log("Frame %i has dist %.3f\n" % (frame, thisDist))
             return frame, thisDist
Beispiel #2
0
def generatePDBs():
    """In a parallel method, generate all of the PDBs of the trajectory"""
    global TOTALFRAMES
    global OUTPATH

    with directory(OUTPATH):

        def generatePDB(frame):
            """Generate the PDB for a certain frame"""
            with open("frame_%i.in" % frame, "w") as script:
                script.write(
                    """parm %s
    trajin %s %i %i 1
    trajout frame_%i.pdb pdb
    """
                    % (PRMTOPPATH, COORDPATH, frame, frame, frame)
                )
            system("cpptraj < frame_%i.in > /dev/null 2> /dev/null" % frame)
            with open("frame_%i.pdb" % frame) as pdb:
                thisDist = rmsdDist(pdbLines=list(pdb), refCoords=REFCOORDS, segments=SEGMENTS)
                log("Frame %i has dist %.3f\n" % (frame, thisDist))
                return frame, thisDist

        log("Generating PDB files.\n")
        distances = parMap(generatePDB, range(1, TOTALFRAMES + 1), n=(cpu_count() / 2), silent=True)

        # clash_screen output sorted by ID
        distances = sorted(distances, key=itemgetter(0))

        # Write output file
        with open(DISTPATH, "w") as dist_vs_t:
            for frameID, dist in distances:
                dist_vs_t.write("%i %.3f\n" % (frameID, dist))

        # Name PDB files
        copy("frame_1.pdb", "initial.pdb")

        for frameID, dist in distances:
            os.rename("frame_%i.pdb" % frameID, "%i.pdb" % frameID)
            unblocked_system("rm frame_%i.in" % frameID)
    unblocked_system("rm reference.pdb")
Beispiel #3
0
def generatePDBs():
    """In a parallel method, generate all of the PDBs of the trajectory"""
    global TOTALFRAMES
    global OUTPATH

    with directory(OUTPATH):
        def generatePDB(frame):
            """Generate the PDB for a certain frame"""
            with open("frame_%i.in" % frame, 'w') as script:
                script.write("""parm %s
    trajin %s %i %i 1
    trajout frame_%i.pdb pdb
    """ % (PRMTOPPATH, COORDPATH, frame, frame, frame))
            system("cpptraj < frame_%i.in > /dev/null 2> /dev/null" % frame)
            with open("frame_%i.pdb" % frame) as pdb:
                thisDist = rmsdDist(pdbLines=list(pdb), refCoords=REFCOORDS, segments=SEGMENTS)
                log("Frame %i has dist %.3f\n" % (frame, thisDist))
                return frame, thisDist

        log("Generating PDB files.\n")
        distances = parMap(generatePDB, range(1, TOTALFRAMES + 1),
                           n=(cpu_count() / 2), silent=True)

        # clash_screen output sorted by ID
        distances = sorted(distances, key=itemgetter(0))

        # Write output file
        with open(DISTPATH, 'w') as dist_vs_t:
            for frameID, dist in distances:
                dist_vs_t.write("%i %.3f\n" % (frameID, dist))

        # Name PDB files
        copy("frame_1.pdb", "initial.pdb")

        for frameID, dist in distances:
            os.rename("frame_%i.pdb" % frameID, "%i.pdb" % frameID)
            unblocked_system("rm frame_%i.in" % frameID)
    unblocked_system("rm reference.pdb")
Beispiel #4
0
def prep():
    """Sets up variables for the entire script. Also detects whether analysis runs are necessary
    and returns a boolean to indicate this."""
    global WORKDIR
    WORKDIR = os.getcwd()
    # Basic verifications
    if args.prmtop is None or args.coord is None:
        fail(RED + UNDERLINE + "Error:" + END + RED +
             " please provide the topology and coordinate files.\n" + END)
    if not os.path.splitext(args.coord)[1].lower() == ".nc":
        fail(RED + UNDERLINE + "Error:" + END + RED +
             " coordinate file extension is invalid. Please specify a binary NetCDF file.\n" + END)

    global PRMTOPPATH
    global COORDPATH
    global OUTPATH
    global DISTPATH
    global REFPRMTOPPATH
    global REFPATH

    # Path modifications
    if not os.path.isabs(args.prmtop):
        PRMTOPPATH = WORKDIR + "/" + args.prmtop
    else:
        PRMTOPPATH = args.prmtop
    if args.refprmtop is None:
        REFPRMTOPPATH = PRMTOPPATH
    elif args.refprmtop is not None and not os.path.isabs(args.refprmtop):
        REFPRMTOPPATH = WORKDIR + "/" + args.refprmtop
    else:
        REFPRMTOPPATH = args.refprmtop
    if not os.path.isabs(args.ref):
        REFPATH = WORKDIR + "/" + args.ref
    else:
        REFPATH = args.ref
    if not os.path.isabs(args.coord):
        COORDPATH = WORKDIR + "/" + args.coord
    else:
        COORDPATH = args.coord
    if not os.path.isabs(args.out):
        OUTPATH = WORKDIR + "/" + args.out
    else:
        OUTPATH = args.out
    if not os.path.isdir(OUTPATH):
        os.mkdir(OUTPATH)
    if not os.path.isabs(args.dist):
        DISTPATH = WORKDIR + "/" + args.dist
    else:
        DISTPATH = args.dist

    global TOTALFRAMES
    TOTALFRAMES = 0

    global SEGMENTS
    if args.segments is None:
        SEGMENTS = []
        log("Will process all segments.\n")
    else:
        error = RED + UNDERLINE + "Error:" + END + \
                RED + ' please provide a valid segment string.\n' + END
        SEGMENTS = eval(args.segments)
        if not isinstance(SEGMENTS, list):
            fail(error)
        for tup in SEGMENTS:
            if not isinstance(tup, tuple) or len(tup) != 2 \
                    or not isinstance(tup[0], int) \
                    or not isinstance(tup[1], int) or tup[0] > tup[1]:
                fail(error)
        log("Will process segments ")
        for tup in SEGMENTS:
            log("%i to %i; " % (tup[0], tup[1]))
        log("\n")