Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.logger.debug("Verify nifty matrix manipulations perform as expected\n")
##matrix manipulations
X=flat(X)
self.assertEqual(X.shape, (6,))
X=row(X)
self.assertEqual(X.shape, (1,6))
X=col(X)
self.assertEqual(X.shape, (6,1))
self.logger.debug("Running some test processes using nifty._exec()\n")
##_exec
self.assertEqual(type(_exec("")),list)
self.assertEqual(_exec("echo test")[0],"test")
_exec("touch .test")
self.assertTrue(os.path.isfile(".test"))
_exec("rm .test")
self.assertFalse(os.path.isfile(".test"))
self.assertRaises(Exception, _exec, "exit 255")
def get_monomer_properties(print_stuff=0):
# Multiply a quantity in nm to convert to a0
nm_to_a0 = 1./0.05291772108
# Multiply a quantity in e*a0 to convert to Debye
ea0_to_debye = 0.393430307
os.system("rm -rf *.log \#*")
_exec(["./grompp"], print_command=False)
_exec(["./mdrun"], outfnm="mdrun.txt", print_command=False)
_exec("./trjconv -f traj.trr -o confout.gro -ndec 6".split(), stdin="0\n", print_command=False)
x = []
q = []
for line in open("confout.gro").readlines():
sline = line.split()
if len(sline) >= 6 and isfloat(sline[3]) and isfloat(sline[4]) and isfloat(sline[5]):
x.append([float(i) for i in sline[3:6]])
for line in open("charges.log").readlines():
sline = line.split()
if 'AtomNr' in line:
q.append(float(sline[5]))
mode = 0
a = []
for line in open("mdrun.txt").readlines():
if mode == 1:
sline = line.split()
if len(sline) == 3:
def get_monomer_properties(print_stuff=0):
# Multiply a quantity in nm to convert to a0
nm_to_a0 = 1./0.05291772108
# Multiply a quantity in e*a0 to convert to Debye
ea0_to_debye = 0.393430307
os.system("rm -rf *.log \#*")
_exec(["./grompp"], print_command=False)
_exec(["./mdrun"], outfnm="mdrun.txt", print_command=False)
_exec("./trjconv -f traj.trr -o confout.gro -ndec 6".split(), stdin="0\n", print_command=False)
x = []
q = []
for line in open("confout.gro").readlines():
sline = line.split()
if len(sline) >= 6 and isfloat(sline[3]) and isfloat(sline[4]) and isfloat(sline[5]):
x.append([float(i) for i in sline[3:6]])
for line in open("charges.log").readlines():
sline = line.split()
if 'AtomNr' in line:
q.append(float(sline[5]))
mode = 0
a = []
for line in open("mdrun.txt").readlines():
if mode == 1:
@param[in] mvals Mathematical parameter values
@param[in] FF ForceBalance force field object
@return E A numpy array of energies in kilojoules per mole
"""
# Part of the command line argument to TINKER.
basename = xyz[:-4]
xin = "%s" % xyz + ("" if tky == None else " -k %s" % tky)
xain = "%s.arc" % basename + ("" if tky == None else " -k %s" % tky)
# Print the force field file from the ForceBalance object, with modified parameters.
FF.make(mvals)
# Execute TINKER.
cmdstr = "./analyze %s" % xain
oanl = _exec(cmdstr,stdin="E",print_command=verbose,print_to_screen=verbose)
# Read potential energy from file.
E = []
for line in oanl:
if 'Total Potential Energy : ' in line:
E.append(float(line.split()[4]))
E = np.array(E) * 4.184
if dipole:
# If desired, read dipole from file.
D = []
for line in oanl:
if 'Dipole X,Y,Z-Components :' in line:
D.append([float(line.split()[i]) for i in range(-3,0)])
D = np.array(D)
# Return a Nx4 array with energies in the first column and dipole in columns 2-4.
answer = np.hstack((E.reshape(-1,1), D.reshape(-1,3)))
def callamber(self, command, stdin=None, print_to_screen=False, print_command=False, **kwargs):
""" Call AMBER; prepend amberhome to calling the appropriate ambertools program. """
csplit = command.split()
# Sometimes the engine changes dirs and the inpcrd/prmtop go missing, so we link it.
# Prepend the AMBER path to the program call.
prog = os.path.join(self.amberhome, "bin", csplit[0])
csplit[0] = prog
# No need to catch exceptions since failed AMBER calculations will return nonzero exit status.
o = _exec(' '.join(csplit), stdin=stdin, print_to_screen=print_to_screen, print_command=print_command, rbytes=1024, **kwargs)
return o
@param[in] AHess Switch to turn on analytic Hessian
@return Answer Contribution to the objective function
"""
Answer = {}
Results = {}
Points = [] # These are the phase points for which data exists.
BPoints = [] # These are the phase points for which we are doing MBAR for the condensed phase.
mBPoints = [] # These are the phase points for which we are doing MBAR for the monomers.
mPoints = [] # These are the phase points to use for enthalpy of vaporization; if we're scanning pressure then set hvap_wt for higher pressures to zero.
tt = 0
for label, PT in zip(self.Labels, self.PhasePoints):
if os.path.exists('./%s/npt_result.p.bz2' % label):
_exec('bunzip2 ./%s/npt_result.p.bz2' % label)
elif os.path.exists('./%s/npt_result.p' % label): pass
else:
logger.warning('In %s :\n' % os.getcwd())
logger.warning('The file ./%s/npt_result.p.bz2 does not exist so we cannot unzip it\n' % label)
if os.path.exists('./%s/npt_result.p' % label):
logger.info('Reading information from ./%s/npt_result.p\n' % label)
Points.append(PT)
Results[tt] = lp_load(open('./%s/npt_result.p' % label))
if 'hvap' in self.RefData and PT[0] not in [i[0] for i in mPoints]:
mPoints.append(PT)
if 'mbar' in self.RefData and PT in self.RefData['mbar'] and self.RefData['mbar'][PT]:
BPoints.append(PT)
if 'hvap' in self.RefData and PT[0] not in [i[0] for i in mBPoints]:
mBPoints.append(PT)
tt += 1
else:
def drive_msms(xyz, radii, density):
with open(os.path.join('msms_input.p'),'w') as f: lp_dump((xyz, radii, density),f)
_exec("CallMSMS.py", print_to_screen=False, print_command=False)
return lp_load(open('msms_output.p'))
str(pt.idnr)), os.getcwd())
# Dump the force field to a pickle file
lp_dump((self.FF, mvals, self.OptionDict, AGrad), 'forcebalance.p')
# Run the simulation chain for point.
cmdstr = ("%s python md_chain.py " % self.mdpfx +
" ".join(self.quantities) + " " +
"--engine %s " % self.engname +
"--length %d " % self.n_sim_chain +
"--name %s " % self.simpfx +
"--temperature %f " % pt.temperature +
"--pressure %f " % pt.pressure +
"--nequil %d " % self.eq_steps +
"--nsteps %d " % self.md_steps)
_exec(cmdstr, copy_stderr=True, outfnm='md_chain.out')
os.chdir('..')
def nvt_simulation(self, temperature):
""" Submit a NVT simulation to the Work Queue. """
wq = getWorkQueue()
if not os.path.exists('nvt_result.p'):
link_dir_contents(os.path.join(self.root,self.rundir),os.getcwd())
cmdstr = '%s python nvt.py %s %.3f' % (self.nptpfx, self.engname, temperature)
if wq is None:
logger.info("Running condensed phase simulation locally.\n")
logger.info("You may tail -f %s/nvt.out in another terminal window\n" % os.getcwd())
_exec(cmdstr, copy_stderr=True, outfnm='nvt.out')
else:
if hasattr(self, 'mol2'):
if hasattr(self, 'FF'):
mol2_send = list(set(self.mol2).difference(set(self.FF.fnms)))
else:
mol2_send = self.mol2
else:
mol2_send = []
queue_up(wq, command = cmdstr+' > nvt.out 2>&1 ',
input_files = self.nvtfiles + self.scripts + mol2_send + ['forcebalance.p'],
output_files = ['nvt_result.p', 'nvt.out'] + self.extra_output, tgt=self)