diff --git a/.gitignore b/.gitignore index e31e431..88e310f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ venv .idea plot - +examples/tmp +examples/run.log diff --git a/examples/data/plumed.dat b/examples/data/plumed.dat new file mode 100644 index 0000000..c1b8b15 --- /dev/null +++ b/examples/data/plumed.dat @@ -0,0 +1,13 @@ +# set up two variables for Phi and Psi dihedral angles +phi: TORSION ATOMS=5,7,9,15 +psi: TORSION ATOMS=7,9,15,17 +# +# Impose an umbrella potential on CV 1 and CV 2 +# with a spring constant of 500 kjoule/mol +# at fixed points on the Ramachandran plot +# +restraint-phi: RESTRAINT ARG=phi KAPPA=100 AT=LAMBDA1 +restraint-psi: RESTRAINT ARG=psi KAPPA=100 AT=LAMBDA2 + +# monitor the two variables and the bias potential from the two restraints +PRINT STRIDE=10 ARG=phi,psi,restraint-phi.bias,restraint-psi.bias FILE=COLVAR UPDATE_FROM=50 diff --git a/examples/data/sim.sh b/examples/data/sim.sh new file mode 100755 index 0000000..217d943 --- /dev/null +++ b/examples/data/sim.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +lambda1=$1 +lambda2=$2 +FOLDER="./tmp/simulations/sim_${lambda1}_${lambda2}" + + +if [ -f $FOLDER/topol.gro ]; then + echo "$FOLDER exists" + exit 0 +fi + +mkdir -p $FOLDER +cp data/plumed.dat $FOLDER +cp data/topol.tpr $FOLDER +sed -i -e "s/LAMBDA1/${lambda1}/g" $FOLDER/plumed.dat +sed -i -e "s/LAMBDA2/${lambda2}/g" $FOLDER/plumed.dat + +cd $FOLDER +source /usr/local/gromacs/bin/GMXRC +gmx --quiet mdrun -deffnm topol -plumed plumed.dat -nsteps 100000 2>&1 +cd ../.. + diff --git a/examples/data/topol.edr b/examples/data/topol.edr new file mode 100644 index 0000000..66b9cb0 Binary files /dev/null and b/examples/data/topol.edr differ diff --git a/examples/data/topol.tpr b/examples/data/topol.tpr new file mode 100644 index 0000000..f049a4f Binary files /dev/null and b/examples/data/topol.tpr differ diff --git a/examples/example.py b/examples/example.py index 0ad6329..f52b67c 100644 --- a/examples/example.py +++ b/examples/example.py @@ -24,11 +24,11 @@ class WHAM2DRunner(UmbrellaRunner): import os from shutil import copyfile - simulation_dir = "simulations" + simulation_dir = "tmp/simulations" print("Collecting sampling data from simulations folder") # collect COLVARs - wham_dir = "WHAM/" + wham_dir = "tmp/WHAM/" if not os.path.exists(wham_dir): os.makedirs(wham_dir) @@ -44,7 +44,7 @@ class WHAM2DRunner(UmbrellaRunner): with open(metadata_file, 'w') as out: for f in os.listdir(simulation_dir): prefix, x, y = f.split("_") - out.write("WHAM/{}.xvg {} {} {} {}\n".format(f, x, y, fc_x, fc_y)) + out.write("{}/{}.xvg {} {} {} {}\n".format(wham_dir, f, x, y, fc_x, fc_y)) # run WHAM2d print("Running WHAM-2d") @@ -101,7 +101,7 @@ class WHAM2DRunner(UmbrellaRunner): class MyUmbrellaRunner(WHAM2DRunner): def after_run_hook(self): - filename = "pmf_{}.pdf".format(self.num_iterations) + filename = "tmp/pmf_{}.pdf".format(self.num_iterations) print("Writing new pmf to {}".format(filename)) pmf_to_plot = deepcopy(self.pmf.T) pmf_to_plot[pmf_to_plot < 0] = None @@ -118,22 +118,21 @@ class MyUmbrellaRunner(WHAM2DRunner): cb = plt.colorbar(pad=0.1) cb.set_label("kJ/mol") plt.savefig(filename) - os.system("cp {} {}".format(filename, "pmf_current.pdf")) + os.system("cp {} {}".format(filename, "tmp/pmf_current.pdf")) def simulate_frames(self, lambdas, frames): print("{} new simulations:".format(len(lambdas))) counter = 0 + if not os.path.exists("tmp"): + os.mkdir('tmp') + threads = [] for f in lambdas: counter += 1 - if os.path.exists("sim/sim_{}_{}/COLVAR".format(*f)): - print("{}) Skipping lambdas={}/{}: COLVAR exists".format(counter, *f)) - continue - print("{}) Simulate lambda1={}, lambda2={}".format(counter, *f)) - command = "bash sim.sh {} {} 2>&1 > run.log".format(*f) + command = "bash data/sim.sh {} {} 2>&1 > tmp/run.log".format(*f) # print("Running {}".format(command)) os.system(command) @@ -147,6 +146,6 @@ runner.cvs_init = (1.4, -1.4) runner.E_min = 10 runner.E_max = 100 runner.E_incr = 10 -runner.max_iterations = 100 +runner.max_iterations = 30 runner.run()