diff --git a/testing/desmond_energies.py b/testing/desmond_energies.py deleted file mode 100644 index 279c6931..00000000 --- a/testing/desmond_energies.py +++ /dev/null @@ -1,111 +0,0 @@ -import subprocess -import os -import pdb -import shutil -import intermol.unit as units -from collections import OrderedDict - -def standardize_key(in_key): - out_key = in_key - # terms from header line - if in_key == 'en': - out_key = 'Raw Potential' - if in_key == 'E_p': - out_key = 'Potential' - if in_key == 'E_k': - out_key = 'Kinetic En.' - if in_key == 'E_x': - out_key = 'Extended En.' - - # terms from (0.000000) lines - if in_key == 'stretch': - out_key = 'Bond' - if in_key == 'angle': - out_key = 'Angle' - if in_key == 'dihedral': - out_key = 'All dihedrals' - if in_key == 'pair_vdw': - out_key = 'LJ-14' - if in_key == 'pair_elec': - out_key = 'Coulomb-14' - if in_key == 'Kinetic': - out_key = '' # already included by header line - if in_key == 'Total': # refers to total potential - out_key = '' # already included by header line - if in_key == 'Self_Energy': - out_key = '' # not sure how it is different from Corr_Energy - return out_key - -def get_desmond_energy_from_file(energy_file): - ''' - parses the desmond energy file - ''' - with open(energy_file, 'r') as f: - data = [] - types = [] - - # first line of enegrp.dat file contains total energy terms - line = f.readline() - if line.startswith('time=0.000000'): # just to make sure the line is what we think it is - terms = line.split() - terms = terms[1:-2] # don't want time, pressure, or volume - for term in terms: - key, value = term.split('=') - types.append(standardize_key(key)) - data.append(float(value)) - - # parse rest of file for individual energy grouops - for line in f: - if '(0.000000)' in line: # time 0 - words = line.split() - if words[-1] == 'total': - continue - key = standardize_key(words[0]) - if key: - types.append(key) - data.append(words[-1]) - data = [float(value) * units.kilocalories_per_mole for value in data] - e_out = OrderedDict(zip(types, data)) - return e_out - -def desmond_energies(cms, cfg, despath): - """ - Evalutes energies of DESMOND files - Args: - cms = cms file - cfg = cfg file - despath = path to DESMOND binaries - - """ - cms = os.path.abspath(cms) - cfg = os.path.abspath(cfg) - direc, cms_filename = os.path.split(cms) - cwd = os.getcwd() - name = os.path.splitext(cms_filename)[0] - energy_file = '%s/%s.enegrp.dat' % (direc, name) - if not despath == '': - desmond_bin = os.path.join(despath,'desmond') - else: - desmond_bin = os.path.join(os.environ.get('SCHRODINGER'),'desmond') - - # use DESMOND To evaluate energy - # cd to directory of cms file so that files generated by desmond - # don't clog the working directory - os.chdir(direc) - if os.path.exists('trj'): - shutil.rmtree('trj') - cmd = [desmond_bin, '-WAIT', '-P', '1', '-in', cms, '-JOBNAME', name, '-c', cfg] - print 'Running DESMOND with command' - print ' '.join(cmd) - with open('desmond_stdout.txt','w') as out, open('desmond_stderr.txt','w') as err: - exit = subprocess.call(cmd, stdout=out, stderr=err) - os.chdir(cwd) - - if exit: # exit status not 0 - raise Exception('Failed evaluating energy of {0}'.format(cms)) - - # parse desmond energy file - tot_energy = get_desmond_energy_from_file(energy_file) - return tot_energy, energy_file - - diff --git a/testing/gromacs_energies.py b/testing/gromacs_energies.py deleted file mode 100644 index c5f3f87c..00000000 --- a/testing/gromacs_energies.py +++ /dev/null @@ -1,113 +0,0 @@ -import subprocess -from collections import OrderedDict -import sys -import os -import pdb - -import intermol.unit as units - -def gromacs_energies(top=None, gro=None, mdp=None, gropath='',grosuff='', grompp_check=False): - """ - - gropath = path to gromacs binaries - grosuff = suffix of gromacs binaries, usually '' or '_d' - - """ - directory, _ = os.path.split(top) - - tpr = os.path.join(directory , 'topol.tpr') - ener = os.path.join(directory , 'ener.edr') - ener_xvg = os.path.join(directory , 'energy.xvg') - conf = os.path.join(directory , 'confout.gro') - mdout = os.path.join(directory , 'mdout.mdp') - state = os.path.join(directory , 'state.cpt') - traj = os.path.join(directory , 'traj.trr') - log = os.path.join(directory , 'md.log') - stdout = os.path.join(directory, 'gromacs_stdout.txt') - stderr = os.path.join(directory, 'gromacs_stderr.txt') - - grompp_bin = os.path.join(gropath, 'grompp' + grosuff) - mdrun_bin = os.path.join(gropath, 'mdrun' + grosuff) - genergy_bin = os.path.join(gropath, 'g_energy' + grosuff) - - # grompp'n it up - cmd = [grompp_bin, '-f', mdp, '-c', gro, '-p', top, '-o', tpr, '-po', mdout, '-maxwarn', '1'] - print 'Running GROMACS with command:' - print ' '.join(cmd) - with open(stdout, 'w') as out, open(stderr, 'w') as err: - exit = subprocess.call(cmd, stdout=out, stderr=err) - if exit: - raise Exception('grompp failed for {0}'.format(top)) - elif grompp_check: - return - - # mdrunin' - cmd = [mdrun_bin, '-nt', '1', '-s', tpr, '-o', traj, '-cpo', state, '-c', - conf, '-e', ener, '-g', log] - print 'Running GROMACS with command:' - print ' '.join(cmd) - with open(stdout, 'wa') as out, open(stderr, 'wa') as err: - exit = subprocess.call(cmd, stdout=out, stderr=err) - if exit: - raise Exception('mdrun failed for {0}'.format(top)) - - # energizin' - select = " ".join(map(str, range(1, 20))) + " 0 " - cmd = 'echo {select} | {genergy_bin} -f {ener} -o {ener_xvg} -dp'.format( - select=select, genergy_bin=genergy_bin, ener=ener, ener_xvg=ener_xvg) - print 'Running GROMACS with command:' - print cmd - with open(stdout, 'wa') as out, open(stderr, 'wa') as err: - exit = subprocess.call(cmd, stdout=out, stderr=err, shell=True) - if exit: - raise Exception('g_energy failed for {0}'.format(top)) - - # extract g_energy output and parse initial energies - with open(ener_xvg) as f: - all_lines = f.readlines() - - types = [] - for line in all_lines: - if line[:3] == '@ s': - types.append(line.split('"')[1]) - - # take last line - data = map(float, all_lines[-1].split()[1:]) # [0] is the time - - # give everything units - data = [value * units.kilojoules_per_mole for value in data] - - # pack it up in a dictionary - e_out = OrderedDict(zip(types, data)) - - # discard non-energy terms - unwanted = ['Kinetic En.', 'Total Energy', 'Temperature', 'Pressure', - 'Volume', 'Box-X', 'Box-Y', 'Box-Z', 'Pres. DC'] - for group in unwanted: - if group in e_out: - del e_out[group] - - # dispersive energies - do buckingham energies also get dumped here? - dispersive = ['LJ (SR)', 'LJ-14', 'Disper.corr.'] - e_out['Dispersive'] = 0 * units.kilojoules_per_mole - for group in dispersive: - if group in e_out: - e_out['Dispersive'] += e_out[group] - - # electrostatic energies - electrostatic = ['Coulomb (SR)', 'Coulomb-14', 'Coul. recip.'] - e_out['Electrostatic'] = 0 * units.kilojoules_per_mole - for group in electrostatic: - if group in e_out: - e_out['Electrostatic'] += e_out[group] - - e_out['Non-bonded'] = e_out['Electrostatic'] + e_out['Dispersive'] - - # all the various dihedral energies - what else goes in here? - all_dihedrals = ['Ryckaert-Bell.', 'Proper Dih.', 'Improper Dih.'] - e_out['All dihedrals'] = 0 * units.kilojoules_per_mole - for group in all_dihedrals: - if group in e_out: - e_out['All dihedrals'] += e_out[group] - - return e_out, ener_xvg diff --git a/testing/lammps_energies.py b/testing/lammps_energies.py deleted file mode 100644 index ac7e4eb4..00000000 --- a/testing/lammps_energies.py +++ /dev/null @@ -1,50 +0,0 @@ -import os -import subprocess -import intermol.unit as units -import pdb - -def lammps_energies(input_file, lmppath='lmp_openmpi', - verbose=False): - """Evaluate energies of LAMMPS files - - Args: - input_file = path to input file (expects data file in same folder) - lmppath = path to LAMMPS binaries - """ - - directory, input_file = os.path.split(input_file) - - # mdrunin' - saved_path = os.getcwd() - os.chdir(directory) - - cmd = "{lmppath} < {input_file}".format( - lmppath=lmppath, input_file=input_file) - with open('lammps_stdout.txt', 'w') as out, open('lammps_stderr.txt', 'w') as err: - exit = subprocess.call(cmd, stdout=out, stderr=err, shell=True) - os.chdir(saved_path) - if exit: - raise Exception('Lammps evaluation failed for {0}'.format(input_file)) - - # energizin' - proc = subprocess.Popen(["awk '/E_bond/{getline; print}' %s/lammps_stdout.txt" % (directory)], - stdout=subprocess.PIPE, shell=True) - (energies, err) = proc.communicate() - if not energies: - raise Exception("Unable to read LAMMPS energy output") - - - # give everything units - data = map(float, energies.split()) - data = [value * units.kilocalories_per_mole for value in data] - - # pack it all up in a dictionary - types = ['Bond', 'Angle', 'Proper Dih.', 'Improper', 'Non-bonded', - 'Dispersive', 'Electrostatic', 'Coul. recip.', 'Disper. corr.', - 'Potential'] - e_out = dict(zip(types, data)) - - # groupings - e_out['Electrostatic'] += e_out['Coul. recip.'] - e_out['All dihedrals'] = e_out['Proper Dih.'] + e_out['Improper'] - return e_out, '%s/lammps_stdout.txt' % directory diff --git a/testing/user_exceptions.py b/testing/user_exceptions.py deleted file mode 100644 index c1c85f9b..00000000 --- a/testing/user_exceptions.py +++ /dev/null @@ -1,29 +0,0 @@ -class Error(Exception): - '''Base class for exceptions in InterMol''' - pass - -class ReadError(Error): - '''Exception raised for errors in reading in input - - Attributes: - type -- input file type - file -- input file in which the error occurred - msg -- explanation of the error - ''' - pass -# def __init__(self, type, file, msg): -# self.expr = expr -# self.msg = msg - -class WriteError(Error): - '''Exception raised for errors in writing output file - - Attributes: - type -- output file type - file -- output file in which the error occurred - msg -- explanation of the error - ''' - - def __init__(self, expr, msg): - self.expr = expr - self.msg = msg