Ejemplo n.º 1
0
import numpy as np
import matplotlib.pyplot as plt

import os
import time

##############################################################################
# Code
##############################################################################

# data_path='/Users/shenglanqiao/Documents/GitHub/waterMD/data'
data_path = os.getcwd()+'/data'
traj = md.load_trr(data_path+'/nvt-pr_run1.trr', top = data_path+'/water-sol_run1.gro')
print ('here is some info about the trajectory we are looking at:')
print traj
test = WaterStats(traj,'run1',read_mod = 'r')

R_water = 0.3

# output_path = '/Users/shenglanqiao/Documents/GitHub/waterMD/output'
output_path = '/home/shenglan/GitHub/waterMD/output'

def test_rdf(r_range):
    test.radial_dist(r_range)
    rs, g_R, g_err = test.rdf[0],test.rdf[1],test.rdf[2]
    fig = plt.figure()
    plt.errorbar(rs,g_R, yerr=g_err)
    plt.title('gn(r)')
    plt.xlabel('r (nm)')
    plt.ylabel('gn(r)')
    plt.ylim(0,max(g_R)*1.2)
Ejemplo n.º 2
0
def main(argv):
    # default values for options
    run_name = None
    outputfile = None
    number_qs = 10
    frame_start = 1
    frame_end = None
    #     q_inverse = 0.3
    q_range = [0.3]
    phi_range = [0, 1.0]

    try:
        opts, args = getopt.getopt(argv, "hi:o:q:r:p:s:e:", [
            "ifile=", "ofile=", "q_inv=", "n_phi=", "phi_range=", "fstart=",
            "fend="
        ])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            usage()
            sys.exit()
        elif opt in ("-i", "--ifile"):
            run_name = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-q", "--q_inv"):
            qs = arg.split('/')
            print qs
            if len(qs) > 1:
                try:
                    q_range = [float(this_q) for this_q in qs]
                except ValueError:
                    print 'Enter a single value of q of a range of values separated by /'
                    sys.exit(2)
            else:
                try:
                    q_range = [float(arg)]
                except ValueError:
                    print 'Enter a single value of q of a range of values separated by space'
                    sys.exit(2)

        elif opt in ("-p", "--n_phi"):
            number_qs = int(arg)
        elif opt in ("-r", "--phi_range"):
            phis = arg.split('/')
            if len(phis) == 2:
                try:
                    phi_range = [float(this_phi) for this_phi in phis]
                except ValueError:
                    print 'Enter two values (in units of pi) for starting and ending phi separated by /. '
                    sys.exit(2)
            else:
                print 'Enter two values (in units of pi) for starting and ending phi separated by /. '
                sys.exit(2)
        elif opt in ("-s", "--fstart"):
            frame_start = int(arg)
        elif opt in ("-e", "--fend"):
            frame_end = int(arg)
    print 'Input run is %s' % run_name
    print 'Output file is %s' % outputfile
    print 'Number of phi used is %d from phi = %.3g pi to phi = %.3g pi' % (
        number_qs, phi_range[0], phi_range[1])
    #     print 'Inverse of q is %.2f nm'%q_inverse
    print 'Computing correlators for the following q_inverse values in nm:'
    print q_range

    if run_name == None:
        print '<runname> must be provided.'
        usage()
        sys.exit(2)


#     data_path = os.getcwd()+'/data'
    data_path = '/home/shenglan/MD_simulations/water_box/cubic_2nm_' + run_name
    traj = md.load_trr(data_path + '/nvt-pr_' + run_name + '.trr',
                       top=data_path + '/water-sol_' + run_name + '.gro')
    print('here is some info about the trajectory we are looking at:')
    print traj
    run = WaterStats(traj, run_name, read_mod='r')
    if frame_start >= run.n_frames:
        print 'Starting frame cannot be greater than the number of frames in simulation.'
        usage()
        sys.exit(2)
    elif frame_end == None:
        frames = np.arange(run.n_frames)[frame_start:]
    else:
        frames = np.arange(run.n_frames)[frame_start:frame_end]

    print("frames %d to %d are used for averaging." % (frames[0], frames[-1]))

    # wavelength of laser
    wavelength = 0.1
    phi = np.linspace(phi_range[0] * np.pi, phi_range[1] * np.pi, number_qs)
    dt = 1.0  # ps
    for q_inverse in q_range:
        print('computing for q_invers = %.3g nm' % q_inverse)
        q = 1 / q_inverse * np.pi * 2.0

        if outputfile == None:
            outputfile = 'corr_'+run_name+\
            '_'+str(q_inverse)+'q_'+str(number_qs)+'p_'+\
            str(frames[0])+\
            '.csv'

        tic = time.clock()
        run.correlator(q,
                       wavelength,
                       frames,
                       phi,
                       cut_off=0.5,
                       output=outputfile)
        toc = time.clock()

        print("Correlator process time for %.3g nm: %.2f" % (q_inverse,
                                                             (toc - tic)))
        outputfile = None

    run.all_tthds.close()
    run.nearest_tthds.close()
Ejemplo n.º 3
0
from water_stats import WaterStats
import numpy as np
import os

import time

##############################################################################
# Code
##############################################################################

run_name = 'run9'
data_path = '/home/shenglan/MD_simulations/water_box/cubic_2nm_run9'
traj = md.load_trr(data_path+'/nvt-pr.trr', top = data_path+'/water-sol.gro')
print ('here is some info about the trajectory we are looking at:')
print traj
ws = WaterStats(traj,run_name)
cut_off = 0.5

tic = time.clock()
for this_frame in range(ws.n_frames):
    tic_loop = time.clock()
    print 'finding tthds for frame %d' % this_frame
    if str(this_frame) in ws.nearest_tthds:
        pass
    else:
        tthds = ws.make_nearest_nb_tthds(cut_off,this_frame)
        ws.nearest_tthds.create_dataset(str(this_frame),data = tthds)
    toc_loop = time.clock()
    print('Total time for this frame: %.2f' %(toc_loop-tic_loop)) 

toc = time.clock()
Ejemplo n.º 4
0
def main(argv):
    # default values for options
    run_name = None
    outputfile = None
    number_qs = 10
    frame_start = 1
    frame_end = None
    #     q_inverse = 0.3
    q_range = [0.3]
    phi_range = [0, 1.0]

    try:
        opts, args = getopt.getopt(
            argv, "hi:o:q:r:p:s:e:", ["ifile=", "ofile=", "q_inv=", "n_phi=", "phi_range=", "fstart=", "fend="]
        )
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == "-h":
            usage()
            sys.exit()
        elif opt in ("-i", "--ifile"):
            run_name = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-q", "--q_inv"):
            qs = arg.split("/")
            print qs
            if len(qs) > 1:
                try:
                    q_range = [float(this_q) for this_q in qs]
                except ValueError:
                    print "Enter a single value of q of a range of values separated by /"
                    sys.exit(2)
            else:
                try:
                    q_range = [float(arg)]
                except ValueError:
                    print "Enter a single value of q of a range of values separated by space"
                    sys.exit(2)

        elif opt in ("-p", "--n_phi"):
            number_qs = int(arg)
        elif opt in ("-r", "--phi_range"):
            phis = arg.split("/")
            if len(phis) == 2:
                try:
                    phi_range = [float(this_phi) for this_phi in phis]
                except ValueError:
                    print "Enter two values (in units of pi) for starting and ending phi separated by /. "
                    sys.exit(2)
            else:
                print "Enter two values (in units of pi) for starting and ending phi separated by /. "
                sys.exit(2)
        elif opt in ("-s", "--fstart"):
            frame_start = int(arg)
        elif opt in ("-e", "--fend"):
            frame_end = int(arg)
    print "Input run is %s" % run_name
    print "Output file is %s" % outputfile
    print "Number of phi used is %d from phi = %.3g pi to phi = %.3g pi" % (number_qs, phi_range[0], phi_range[1])
    #     print 'Inverse of q is %.2f nm'%q_inverse
    print "Computing correlators for the following q_inverse values in nm:"
    print q_range

    if run_name == None:
        print "<runname> must be provided."
        usage()
        sys.exit(2)

    #     data_path = os.getcwd()+'/data'
    data_path = "/home/shenglan/MD_simulations/water_box/cubic_2nm_" + run_name
    traj = md.load_trr(data_path + "/nvt-pr_" + run_name + ".trr", top=data_path + "/water-sol_" + run_name + ".gro")
    print ("here is some info about the trajectory we are looking at:")
    print traj
    run = WaterStats(traj, run_name, read_mod="r")
    if frame_start >= run.n_frames:
        print "Starting frame cannot be greater than the number of frames in simulation."
        usage()
        sys.exit(2)
    elif frame_end == None:
        frames = np.arange(run.n_frames)[frame_start:]
    else:
        frames = np.arange(run.n_frames)[frame_start:frame_end]

    print ("frames %d to %d are used for averaging." % (frames[0], frames[-1]))

    # wavelength of laser
    wavelength = 0.1
    phi = np.linspace(phi_range[0] * np.pi, phi_range[1] * np.pi, number_qs)
    dt = 1.0  # ps
    for q_inverse in q_range:
        print ("computing for q_invers = %.3g nm" % q_inverse)
        q = 1 / q_inverse * np.pi * 2.0

        if outputfile == None:
            outputfile = (
                "corr_" + run_name + "_" + str(q_inverse) + "q_" + str(number_qs) + "p_" + str(frames[0]) + ".csv"
            )

        tic = time.clock()
        run.correlator(q, wavelength, frames, phi, cut_off=0.5, output=outputfile)
        toc = time.clock()

        print ("Correlator process time for %.3g nm: %.2f" % (q_inverse, (toc - tic)))
        outputfile = None

    run.all_tthds.close()
    run.nearest_tthds.close()
Ejemplo n.º 5
0
from water_stats import WaterStats
import numpy as np
import os

import time

##############################################################################
# Code
##############################################################################

run_name = 'run9'
data_path = '/home/shenglan/MD_simulations/water_box/cubic_2nm_run9'
traj = md.load_trr(data_path + '/nvt-pr.trr', top=data_path + '/water-sol.gro')
print('here is some info about the trajectory we are looking at:')
print traj
ws = WaterStats(traj, run_name)
cut_off = 0.5

tic = time.clock()
for this_frame in range(ws.n_frames):
    tic_loop = time.clock()
    print 'finding tthds for frame %d' % this_frame
    if str(this_frame) in ws.nearest_tthds:
        pass
    else:
        tthds = ws.make_nearest_nb_tthds(cut_off, this_frame)
        ws.nearest_tthds.create_dataset(str(this_frame), data=tthds)
    toc_loop = time.clock()
    print('Total time for this frame: %.2f' % (toc_loop - tic_loop))

toc = time.clock()
Ejemplo n.º 6
0
import matplotlib.pyplot as plt

import os
import time

##############################################################################
# Code
##############################################################################

# data_path='/Users/shenglanqiao/Documents/GitHub/waterMD/data'
data_path = os.getcwd() + '/data'
traj = md.load_trr(data_path + '/nvt-pr_run1.trr',
                   top=data_path + '/water-sol_run1.gro')
print('here is some info about the trajectory we are looking at:')
print traj
test = WaterStats(traj, 'run1', read_mod='r')

R_water = 0.3

# output_path = '/Users/shenglanqiao/Documents/GitHub/waterMD/output'
output_path = '/home/shenglan/GitHub/waterMD/output'


def test_rdf(r_range):
    test.radial_dist(r_range)
    rs, g_R, g_err = test.rdf[0], test.rdf[1], test.rdf[2]
    fig = plt.figure()
    plt.errorbar(rs, g_R, yerr=g_err)
    plt.title('gn(r)')
    plt.xlabel('r (nm)')
    plt.ylabel('gn(r)')
Ejemplo n.º 7
0
import h5py
from water_stats import WaterStats
import numpy as np
import os

##############################################################################
# Code
##############################################################################

run_name = "run4"
data_path = os.getcwd() + "/data"
traj = md.load_trr(data_path + "/nvt-pr_" + run_name + ".trr", top=data_path + "/water-sol_" + run_name + ".gro")
print ("here is some info about the trajectory we are looking at:")
print traj
ws = WaterStats(traj, run_name)
cut_off = 0.5

for this_frame in range(ws.n_frames):
    if str(this_frame) in ws.all_tthds:
        pass
    else:
        tthds = []
        for this_water in ws.water_inds:
            tthds.extend(ws.make_tthd(this_water, cut_off, this_frame))
        ws.all_tthds.create_dataset(str(this_frame), data=tthds)

# print len(tthds)
# print tthds[0][0]

Ejemplo n.º 8
0
import h5py
from water_stats import WaterStats
import numpy as np
import os

##############################################################################
# Code
##############################################################################

run_name = 'run4'
data_path = os.getcwd() + '/data'
traj = md.load_trr(data_path + '/nvt-pr_' + run_name + '.trr',
                   top=data_path + '/water-sol_' + run_name + '.gro')
print('here is some info about the trajectory we are looking at:')
print traj
ws = WaterStats(traj, run_name)
cut_off = 0.5

for this_frame in range(ws.n_frames):
    if str(this_frame) in ws.all_tthds:
        pass
    else:
        tthds = []
        for this_water in ws.water_inds:
            tthds.extend(ws.make_tthd(this_water, cut_off, this_frame))
        ws.all_tthds.create_dataset(str(this_frame), data=tthds)

# print len(tthds)
# print tthds[0][0]

#ws.all_tthds['1'][:]= tthds
Ejemplo n.º 9
0
from water_stats import WaterStats
import numpy as np
import os

import time

##############################################################################
# Code
##############################################################################

run_name = 'run5'
data_path = os.getcwd()+'/data'
traj = md.load_trr(data_path+'/nvt-pr_'+run_name+'.trr', top = data_path+'/water-sol_'+run_name+'.gro')
print ('here is some info about the trajectory we are looking at:')
print traj
ws = WaterStats(traj,run_name)
cut_off = 0.5
frame_ind = 1

half_box = ws.traj.unitcell_lengths[0][0]/2.*10

inds = range(1001)[101:]
count = 33897
for frame_ind in inds:
    nbs = ws.find_nearest_nbs(cut_off,frame_ind,3)
    xyz_pos = ws.traj[frame_ind].xyz
    
    with open(os.getcwd()+'/output_data/tthd_pdb_1000.pdb','a') as f:
        for this_nb in nbs:
            
            r1 = xyz_pos[0,this_nb[0],:]*10