Commit 1d4edc3a authored by cmaffeo2's avatar cmaffeo2
Browse files

Update some camel case to be pythonic

parent 967b04d8
# -*- coding: utf-8 -*-
import sys
from glob import glob
import re
from mrdna.readers import cadnano_reader()
from mrdna.simulate import run_multiresolution_simulation as simulate
if __name__ == '__main__':
if len(sys.argv) > 1:
json_files = sys.argv[1:]
else:
print(len(sys.argv))
json_files = glob('json/*')
for f in json_files:
print("Working on {}".format(f))
out = re.match('json/(.*).json',f).group(1)
try:
data = read_json_file(f)
model = read_model(data)
except:
print("WARNING: skipping unreadable json file {}".format(f))
continue
directory = "run.out.7bd92d9.twist-angles"
simulate( model,
output_name = out,
coarse_steps = 1e7,
fine_steps = 1e7,
gpu=1,
directory = directory
)
......@@ -676,9 +676,9 @@ class ArbdModel(PdbModel):
if typeA != typeB:
self.nbSchemes.append( (nbScheme, typeB, typeA) )
def simulate(self, outputPrefix, outputDirectory='output', numSteps=100000000, timestep=None, gpu=0, outputPeriod=1e4, arbd=None, directory='.'):
def simulate(self, output_name, output_directory='output', num_steps=100000000, timestep=None, gpu=0, output_period=1e4, arbd=None, directory='.'):
assert(type(gpu) is int)
numSteps = int(numSteps)
num_steps = int(num_steps)
d_orig = os.getcwd()
try:
......@@ -693,7 +693,7 @@ class ArbdModel(PdbModel):
self._countParticleTypes()
self._updateParticleOrder()
if outputDirectory == '': outputDirectory='.'
if output_directory == '': output_directory='.'
if arbd is None:
for path in os.environ["PATH"].split(os.pathsep):
......@@ -712,19 +712,19 @@ class ArbdModel(PdbModel):
if not os.access(arbd, os.X_OK):
raise Exception("ARBD is not executable")
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
elif not os.path.isdir(outputDirectory):
raise Exception("outputDirectory '%s' is not a directory!" % outputDirectory)
if not os.path.exists(output_directory):
os.makedirs(output_directory)
elif not os.path.isdir(output_directory):
raise Exception("output_directory '%s' is not a directory!" % output_directory)
self.writePdb( outputPrefix + ".pdb" )
self.writePsf( outputPrefix + ".psf" )
self.writeArbdFiles( outputPrefix, numSteps=numSteps, outputPeriod=outputPeriod )
self.writePdb( output_name + ".pdb" )
self.writePsf( output_name + ".psf" )
self.writeArbdFiles( output_name, numSteps=num_steps, outputPeriod=output_period )
os.sync()
## http://stackoverflow.com/questions/18421757/live-output-from-subprocess-command
cmd = (arbd, '-g', "%d" % gpu, "%s.bd" % outputPrefix, "%s/%s" % (outputDirectory, outputPrefix))
cmd = (arbd, '-g', "%d" % gpu, "%s.bd" % output_name, "%s/%s" % (output_directory, output_name))
cmd = tuple(str(x) for x in cmd)
print("Running ARBD with: %s" % " ".join(cmd))
......@@ -987,7 +987,7 @@ component "data" value 3
## TODO: cache coordinates using numpy arrays for quick min/max
raise(NotImplementedError)
def write_namd_configuration( self, output_prefix, num_steps = 1e6,
def write_namd_configuration( self, output_name, num_steps = 1e6,
output_directory = 'output',
update_dimensions=True, extrabonds=True ):
......@@ -1014,10 +1014,10 @@ tclForcesScript $prefix.forces.tcl
format_data['origin'+k] = -v*0.5
format_data['cell'+k] = v
format_data['prefix'] = output_prefix
format_data['prefix'] = output_name
format_data['num_steps'] = int(num_steps//12)*12
format_data['output_directory'] = output_directory
filename = '{}.namd'.format(output_prefix)
filename = '{}.namd'.format(output_name)
with open(filename,'w') as fh:
fh.write("""
......@@ -1114,13 +1114,13 @@ if {{$nLast == 0}} {{
run {num_steps:d}
""".format(**format_data))
def atomic_simulate(self, outputPrefix, outputDirectory='output'):
def atomic_simulate(self, output_name, output_directory='output'):
if self.cacheUpToDate == False: # TODO: remove cache?
self._countParticleTypes()
self._updateParticleOrder()
if outputDirectory == '': outputDirectory='.'
self.writePdb( outputPrefix + ".pdb" )
self.writePsf( outputPrefix + ".psf" )
self.write_namd_configuration( outputPrefix, output_directory = outputDirectory )
if output_directory == '': output_directory='.'
self.writePdb( output_name + ".pdb" )
self.writePsf( output_name + ".psf" )
self.write_namd_configuration( output_name, output_directory = output_directory )
os.sync()
......@@ -2376,7 +2376,7 @@ class SegmentModel(ArbdModel):
for s in self.strands:
s.update_atomic_orientations(orientation)
def write_atomic_ENM(self, prefix, lattice_type=None):
def write_atomic_ENM(self, output_name, lattice_type=None):
## TODO: ensure atomic model was generated already
if lattice_type is None:
try:
......@@ -2394,7 +2394,7 @@ class SegmentModel(ArbdModel):
## TODO: allow ENM to be created without first building atomic model
noStackPrime = 0
noBasepair = 0
with open("%s.exb" % prefix,'w') as fh:
with open("%s.exb" % output_name,'w') as fh:
# natoms=0
for seg in self.segments:
......@@ -2523,13 +2523,13 @@ class SegmentModel(ArbdModel):
print("PUSH BONDS:", len(push_bonds))
if not self.useTclForces:
with open("%s.exb" % prefix, 'a') as fh:
with open("%s.exb" % output_name, 'a') as fh:
for i,j in push_bonds:
fh.write("bond %d %d %f %.2f\n" % (i,j,1.0,31))
else:
flat_push_bonds = list(sum(push_bonds))
atomList = list(set( flat_push_bonds ))
with open("%s.forces.tcl" % prefix,'w') as fh:
with open("%s.forces.tcl" % output_name,'w') as fh:
fh.write("set atomList {%s}\n\n" %
" ".join([str(x-1) for x in atomList]) )
fh.write("set bonds {%s}\n" %
......
......@@ -36,7 +36,7 @@ def multiresolution_simulation( model, output_name,
# TODO: add the output directory in to the readArbdCoords functions or make it an attribute of the model object
""" Coarse simulation """
simargs = dict(timestep=200e-6, outputPeriod=coarse_output_period, gpu=gpu)
simargs = dict(timestep=200e-6, output_period=coarse_output_period, gpu=gpu)
model._clear_beads()
model._generate_bead_model( 5, 5, local_twist=False )
......@@ -45,18 +45,18 @@ def multiresolution_simulation( model, output_name,
output_prefix = "%s-0" % output_name
full_output_prefix = "%s/%s" % (output_directory,output_prefix)
## TODO Remove long bonds
model.simulate( outputPrefix = output_prefix, numSteps=0.05*coarse_steps, **simargs )
model.simulate( output_name = output_prefix, numSteps=0.05*coarse_steps, **simargs )
try:
coordinates = readArbdCoords('%s.restart' % full_output_prefix)
except:
coordinates = readArbdCoords('%s.0.restart' % full_output_prefix)
output_prefix = "%s-1" % output_name
model.update_splines(coordinates)
model.simulate( outputPrefix = output_prefix, numSteps=0.95*coarse_steps, **simargs )
model.simulate( output_prefix = output_prefix, num_steps=0.95*coarse_steps, **simargs )
else:
output_prefix = "%s-1" % output_name
full_output_prefix = "%s/%s" % (output_directory,output_prefix)
model.simulate( outputPrefix = output_prefix, numSteps=coarse_steps, **simargs )
model.simulate( output_name = output_prefix, num_steps=coarse_steps, **simargs )
try:
coordinates = readArbdCoords('%s.restart' % full_output_prefix)
except:
......@@ -67,11 +67,11 @@ def multiresolution_simulation( model, output_name,
output_prefix = "%s-2" % output_name
full_output_prefix = "%s/%s" % (output_directory,output_prefix)
simargs['timestep'] = 50e-6
simargs['outputPeriod'] = fine_output_period
simargs['output_period'] = fine_output_period
model.update_splines(coordinates)
model._clear_beads()
model._generate_bead_model( 1, 1, local_twist=True, escapable_twist=True )
model.simulate( outputPrefix = output_prefix, numSteps=fine_steps, **simargs )
model.simulate( output_name = output_prefix, num_steps=fine_steps, **simargs )
try:
coordinates = readAvgArbdCoords('%s.psf' % output_prefix,'%s.pdb' % output_prefix, '%s.dcd' % full_output_prefix, rmsdThreshold=1)
except:
......@@ -84,7 +84,7 @@ def multiresolution_simulation( model, output_name,
model.update_splines(coordinates)
model._clear_beads()
model._generate_bead_model( 1, 1, local_twist=True, escapable_twist=False )
model.simulate( outputPrefix = output_prefix, numSteps=fine_steps, **simargs )
model.simulate( output_name = output_prefix, num_steps=fine_steps, **simargs )
try:
coordinates = readAvgArbdCoords('%s.psf' % output_prefix,'%s.pdb' % output_prefix, '%s.dcd' % full_output_prefix )
except:
......@@ -97,8 +97,8 @@ def multiresolution_simulation( model, output_name,
model.update_splines(coordinates)
model._clear_beads()
model._generate_atomic_model(scale=backbone_scale)
model.write_atomic_ENM( output_prefix )
model.atomic_simulate( outputPrefix = output_prefix )
model.write_atomic_ENM( output_name )
model.atomic_simulate( output_name = output_prefix )
ret = directory
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment