Skip to content

Commit

Permalink
added packmol to environment and changed the default behavior of the …
Browse files Browse the repository at this point in the history
…REMD simulations to chdir into the working directory and run packmol there, rather than running from the top directory. fortran seems to have a limit on the string length it can use, so I cannot feed packmol long abspath file names
  • Loading branch information
tlfobe authored and tlfobe committed Feb 22, 2024
1 parent 90dcf36 commit 27d01af
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
26 changes: 1 addition & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@
except:
long_description = "\n".join(short_description[2:]),

class PostDevelopCommand(develop):
"""Post-installation for development mode."""
def run(self):
develop.run(self)
start_dir = os.path.abspath('')
os.chdir('submodules/packmol')
check_call('./configure'.split())
check_call('make'.split())
os.chdir(start_dir)
# PUT YOUR POST-INSTALL SCRIPT HERE or CALL A FUNCTION

class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
start_dir = os.path.abspath('')
os.chdir('submodules/packmol')
check_call('./configure'.split())
check_call('make'.split())
os.chdir(start_dir)

setup(
# Self-descriptive entries which should always be present
name='terphenyl_simulations',
Expand All @@ -56,10 +35,7 @@ def run(self):
long_description=long_description,
long_description_content_type="text/markdown",
version=versioneer.get_version(),
cmdclass={
'develop': PostDevelopCommand,
'install': PostInstallCommand,
},
cmdclass=versioneer.get_cmdclass(),
license='MIT',

# Which Python importable modules should be included when your package is installed
Expand Down
13 changes: 12 additions & 1 deletion terphenyl_simulations/analysis_workflows/remd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,26 @@ def build_foldamer(job):
foldamer_builder = terphenyl_simulations.build.FoldamerBuilder(job.sp['build_foldamer'])
foldamer_builder.build_foldamer(path = job.fn(""))

@FlowProject.pre.after(build_foldamer)
@FlowProject.operation
def parameterize_foldamer(job):
pass

@FlowProject.post((lambda job: os.path.exists(job.fn('solvated_' + job.doc['build_parameters']['structure_file'] + '.pdb'))))
@FlowProject.operation
def build_system(job):
packmol_builder = terphenyl_simulations.build.SystemBuilder(job.sp['build_foldamer'], path = job.fn(''))
top_dir = os.path.abspath('.')
os.chdir(job.fn(''))
packmol_builder = terphenyl_simulations.build.SystemBuilder(job.sp['build_foldamer'])
packmol_builder.build_packmol_inp()
packmol_builder.build_system()
os.chdir(top_dir)

@FlowProject.pre.after(build_system)
@FlowProject.operation
def parameterize_system(job):
pass


def main():
if not os.path.isdir('workspace'):
Expand Down
36 changes: 24 additions & 12 deletions terphenyl_simulations/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ def build_packmol_inp(self):
self.output_file
)

# Get solvent PDB location

# Check top signac directory
solvent_pdb = self.build_params['system']['solvent'] + '.pdb'
print(os.listdir(os.path.join(ROOT_DIR, 'data/solvents/')))

# Check stored solvent pdbs
if not os.path.exists(solvent_pdb) and solvent_pdb in os.listdir(os.path.join(ROOT_DIR, 'data/solvents/')):
print('Using ' + solvent_pdb + ' from the internal library of solvents. If this ' + \
'is not the behavior you intend, please include the solvent pdb you wish ' + \
'to solvate the system with in your working directory.')
solvent_pdb = os.path.join(ROOT_DIR, 'data/solvents/', self.build_params['system']['solvent'] + '.pdb')

# Copy to path directory
shutil.copy(
solvent_pdb,
os.path.join(self.path, solvent_pdb.split('/')[-1])
)
else:
warnings.warn('Warning! Unable to find ' + solvent_pdb + ' in the working directory \
or the internal library.')


# Make replacements to the template inp file
replace_all_pattern('OUTPUT_FILENAME', os.path.join(self.path, 'solvated_' + self.build_params['structure_file'] + '.pdb'), self.output_file)
replace_all_pattern('SOLUTE_PDB', os.path.join(self.path, self.build_params['structure_file'] + '.pdb'), self.output_file)
Expand All @@ -100,18 +123,6 @@ def build_packmol_inp(self):
]
solute_position_str = [str(round(n, 1)) for n in solute_position]
replace_all_pattern('SOLUTE_POSITION', ' '.join(solute_position_str), self.output_file)

# Get solvent PDB location
solvent_pdb = self.build_params['system']['solvent'] + '.pdb'
print(os.listdir(os.path.join(ROOT_DIR, 'data/solvents/')))
if not os.path.exists(solvent_pdb) and solvent_pdb in os.listdir(os.path.join(ROOT_DIR, 'data/solvents/')):
print('Using ' + solvent_pdb + ' from the internal library of solvents. If this ' + \
'is not the behavior you intend, please include the solvent pdb you wish ' + \
'to solvate the system with in your working directory.')
solvent_pdb = os.path.join(ROOT_DIR, 'data/solvents/', self.build_params['system']['solvent'] + '.pdb')
else:
warnings.warn('Warning! Unable to find ' + solvent_pdb + ' in the working directory \
or the internal library.')
replace_all_pattern('SOLVENT_PDB', solvent_pdb, self.output_file)
replace_all_pattern('N_SOLVENT', str(self.build_params['system']['n_solvent']), self.output_file)

Expand All @@ -133,6 +144,7 @@ def build_system(self):
with open('temp', 'w') as f:
f.write(cmdline_entry)

print(cmdline_entry)
process = Popen(['bash temp'], shell = True, stdin=PIPE)
process.wait()
os.remove('temp')
Expand Down
4 changes: 2 additions & 2 deletions terphenyl_simulations/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def torsion_clustering_grid_search(
min_samples_values,
[round(eps, 2) for eps in eps_values],
"Min. Samples",
"$\epsilon_{DBSCAN}$",
"$\\epsilon_{DBSCAN}$",
prefix + "_" + plot_filename,
"Avg. Silhouette Score"
)
Expand Down Expand Up @@ -368,7 +368,7 @@ def clustering_grid_search(
min_samples_values,
[round(eps, 2) for eps in eps_values],
"Min. Samples",
"$\epsilon_{DBSCAN}$",
"$\\epsilon_{DBSCAN}$",
prefix + "_" + plot_filename,
"Avg. Silhouette Score"
)
Expand Down
4 changes: 2 additions & 2 deletions terphenyl_simulations/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def plot_ramachandran_plot(traj_file, top_file, prefix = "remd", bins = 50, titl

plt.figure(figsize=[5,5])
plt.hist2d(phi_angles, psi_angles, bins = np.linspace(-180, 180, bins + 1))
plt.xlabel("$\Phi$ Angle (Degrees)")
plt.ylabel("$\Psi$ Angle (Degrees)")
plt.xlabel("$\\Phi$ Angle (Degrees)")
plt.ylabel("$\\Psi$ Angle (Degrees)")

for scatter_points_file in scatter_points_files:
frame = md.load(scatter_points_file)
Expand Down

0 comments on commit 27d01af

Please sign in to comment.