reproduceable tmp pmfs

This commit is contained in:
daniel
2020-07-06 11:33:28 +02:00
parent 4b2a12f742
commit 4f38e2a780
2 changed files with 22 additions and 16 deletions

View File

@@ -47,7 +47,6 @@ class UmbrellaRunner():
pmf = np.empty(shape)
pmf.fill(-1)
return pmf
def _get_lambdas_for_index(self, idx):
""" takes a coordinate tuple of the pmf and returns corresponding lambda values """
@@ -68,10 +67,21 @@ class UmbrellaRunner():
if abs(r[i]-lambdas[dimen]) < 0.00001:
idx.append(i)
break
if len(idx) == len(lambdas):
return tuple(idx)
else: # if len differs, theres no index for every dimension
raise ValueError("{} has no index.".format(lambdas))
if not len(idx)-1 == dimen:
raise ValueError(f"{lambdas} has no index because {lambdas[dimen]} is not in {r}.")
return tuple(idx)
def _get_sampled_lambdas(self, step=None):
""" returns an array of all sampled lambdas. If step is given, only return
lambdas for this step"""
if step is None:
sampled_coords = np.where(self.sample_list > 0)
else:
sampled_coords = np.where(self.sample_list == step)
sampled_coords = np.array(sampled_coords).T
return np.array([self._get_lambdas_for_index(cvs) for cvs in sampled_coords])
def _get_root_frames(self, pmf, frames, E_max):
""" returns the index of all positions in the pmf where the energy is

View File

@@ -33,18 +33,14 @@ class WHAM2DRunner(UmbrellaRunner):
""" create the metadata file for wham-2d """
path = os.path.join(self.tmp_folder, "{}_metadata.dat".format(self.num_iterations))
with open(path, 'w') as out:
for file in os.listdir(self.simulation_folder):
filepath = os.path.join(self.simulation_folder, file, "COLVAR")
if not os.path.exists(filepath) and self.verbose:
print("Not found: {}".format(filepath))
for x, y in self._get_sampled_lambdas():
colvar_file = os.path.join(self.simulation_folder, f"umb_{x}_{y}", "COLVAR")
if not os.path.exists(colvar_file) and self.verbose:
print("Not found: {}".format(colvar_file))
continue
prefix, x, y = file.split("_")
index = self._get_index_for_lambdas((float(x),float(y)))
if self.sample_list[index] != 0:
colvar_file = os.path.join(file, 'COLVAR')
out.write("{file}\t{x}\t{y}\t{fc_x}\t{fc_y}\n".format(
file=os.path.join(self.simulation_folder, colvar_file), x=x, y=y, fc_x=self.whamconfig['fc_x'], fc_y=self.whamconfig['fc_y']
))
out.write("{file}\t{x}\t{y}\t{fc_x}\t{fc_y}\n".format(
file=colvar_file, x=x, y=y, fc_x=self.whamconfig['fc_x'], fc_y=self.whamconfig['fc_y']
))
return path