def read_mddata():
    """ Read the xtc and trajectory file using MDreader
    """
    mdsys = mdreader.MDreader()
    mdsys.do_parse()
    print "Done"
    return mdsys
Ejemplo n.º 2
0
    lipids = ['DIPC', 'DPPC', 'CHOL']

    # --------------------------------------------------------------------------
    # Create a logger
    memsurfer.utils.create_logger(2, 1, 0, '', '')

    # The prefix we will use to name the output files
    outprefix = args['traj'][0]
    outprefix = outprefix[:outprefix.rfind('.')]

    # --------------------------------------------------------------------------
    # Use MDAnalysis to read the data
    fargs = ['-f', args['traj'][0], '-s', args['topo'][0]]
    LOGGER.info('arguments = {}'.format(fargs))

    syst = mdreader.MDreader(fargs)
    syst.add_argument('-sframe',
                      metavar='SELFRAME',
                      type=int,
                      dest='selframe',
                      default=-1,
                      help='int \tframe to save')
    syst.do_parse()

    LOGGER.info('Number of frames in sim {}'.format(len(syst)))
    LOGGER.info('System dimensions: {}'.format(syst.dimensions[0:3]))

    # In this example, we only look at a single frame (the last one)
    selFrame = [len(syst) - 1]

    # Our domain is periodic (in xy)
Ejemplo n.º 3
0
#!/usr/bin/env python
import mdreader
import numpy
"""
A simple example of a calculation done every frame on the coordinates
of predefined groups. (the angle of a bond with the Z axis).
"""

md = mdreader.MDreader()

topNC3 = md.select_atoms("name NC3 and prop z > 200")
topPO4 = md.select_atoms("name PO4 and prop z > 200")
nbonds = len(topNC3)

angles = numpy.empty(
    (len(md),
     nbonds))  # Angle data will be appended as the trajectory is parsed
#  len(md) returns the total number of frames

for fm in md.iterate(p=1):
    # The power of NumPy
    vecs = topPO4.positions - topNC3.positions  # vecs'  shape is (700,3)
    norms = numpy.hypot.reduce(vecs, axis=1)  # norms' shape is (700,)
    frame_angs = (180 / numpy.pi) * numpy.arccos(
        vecs[:, 2] / norms)  # ":" notation: all the values of the axis
    angles[fm.frame, :] = frame_angs  # direct assigment to the results array

numpy.savetxt(md.opts.outfile, angles)  # Save data to file
Ejemplo n.º 4
0
    if phase_sign <0:
        phase = -phase
    roll = RollTiltAngle*np.cos(np.radians(phase))
    tilt = RollTiltAngle*np.sin(np.radians(phase))
    
    return om, Rm.reshape(1,9), shift, slide, rise, tilt, roll, twist

def write2json(data, file):
    d = np.swapaxes(data,2,0)
    dlist = d.tolist()
    with open(mol.opts.outfile+"_"+file+".json", 'w') as outfile:
        json.dump(dlist, outfile)
    
# input files
library_path = "./data/"
mol = mdreader.MDreader(description='Calculate helical parameters for dsDNA')
mol.setargs(o="")

total_res = len(mol.residues)
basepairs = total_res/2
steps = (total_res/2)-1
print "Residues:",total_res,"Snapshots:",len(mol.trajectory)-1

base_ori,base_orient = np.empty((total_res,3)),np.empty((total_res,9))
basepair_parameters = np.empty((basepairs,6))
local_parameters = np.zeros((steps,6))
step_parameters = np.empty((steps,6))
def get_params():
    #########################
    # Bases frame
    #########################
Ejemplo n.º 5
0
    ])
except getopt.GetoptError as err:
    print(err)
    sys.exit(2)

for opt, arg in opts:
    if opt == '-h':
        print(usage)
        exit(2)

#################################################################################
###############################  START OF SCRIPT  ###############################
#################################################################################

resultFile = open(outDir + 'analysisResults.txt', "w+")
syst = mdreader.MDreader()

# Parse bilayer composition
lipidNameList, leaflet_down, leaflet_up, asym = parse_bilayer_composition()
resultFile.write(f"Asymmetry {asym}\n\n")

# Parse simulation parameters
totalSimulationTime, temperature = parse_md_param()

# Create new index file grouped by lipid headgroup
selString = "(echo del 0-100; echo a PO4 NH3 CNO ROH; echo name 0 headgroups; echo q)"
headgroupsFP = outDir + 'headgroups.ndx'
createIndexFile(selString, indFP, headgroupsFP)

# Separate bilayer by leaflet into two index files using fatslim
leafletsFP = outDir + 'bilayer_leaflet_0000.ndx'
#!/usr/bin/env python
import mdreader
import numpy
"""
A simple example of a calculation done every frame on the coordinates
of groups chosen from an index. (the angle of a bond with the Z axis).
Iteration is done in parallel, and results must be manually gathered.
(A future improvement will be the automatic handling of these cases).
"""

md = mdreader.MDreader(internal_argparse=False)
md.setargs(s="start.gro")
# An index will now be expected from the user
md.add_ndx(ndxparms=["Select cholines", "Select phosphates"], ndxdefault='index.ndx') 

nbonds = len(md.ndxgs[0])
if len(md.ndxgs[0]) != len(md.ndxgs[1]):
    raise ValueError("Both groups must have the same number of atoms.")

# The function that will be called every frame, distributed by all workers.
#  Only the returned values will be available to the calling script.
def calc_frame_angles():
    vecs = md.ndxgs[1].positions - md.ndxgs[0].positions
    norms = numpy.hypot.reduce(vecs, axis=1)
    return (180/numpy.pi)*numpy.arccos(vecs[:,2]/norms)

result = md.do_in_parallel(calc_frame_angles)   # Result is now a list of as many elements as frames,
                                                #  each being a returned value from the called function.
angles = numpy.array(result)    # Gathering the results in an array.
numpy.savetxt(md.opts.outfile, angles)
Ejemplo n.º 7
0
        self.XVG.close()
        self.CXVG.close()
        if self.syst.opts.verbose:
            sys.stderr.write("TOTAL:\t")
            sys.stderr.write(("%d\t" * 4) % tuple(self.total_tally))
            if self.syst.opts.qc:
                sys.stderr.write(("%d\t" * 17) % tuple(self.total_jtype))
            sys.stderr.write("\n")


#
##################################################################
##################################################################

if __name__ == "__main__":
    syst = mdreader.MDreader(description=ver)
    ## Options
    #syst.add_argument('-o', metavar='OUT', dest='outfile', default='flux.xvg',
    #    help = 'file\tThe flux vs time file. Read the --help for the meaning '
    #                 'of each column in the output.')
    syst.add_argument(
        '-oc',
        metavar='OUT',
        dest='cumfile',
        default='flux-cumul.xvg',
        help='file\tThe cumulative flux vs time file. Columns are: time, '
        'total flux, upward flux, downward flux.')
    syst.add_argument('-atname',
                      metavar='NAME',
                      dest='watername',
                      default='W',