Skip to content

Commit

Permalink
Tweaked analyze_traj.py and clustering.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wehs7661 committed Aug 20, 2023
1 parent 4fb2144 commit ee7d377
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
4 changes: 3 additions & 1 deletion ensemble_md/analysis/analyze_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def stitch_trajs(gmx_executable, files, rep_trajs):
arguments = [gmx_executable, 'trjcat', '-f']
arguments.extend(files_sorted[i])
arguments.extend(['-o', f'traj_{i}.xtc'])
utils.run_gmx_cmd(arguments)
returncode, stdout, stderr = utils.run_gmx_cmd(arguments)
if returncode != 0:
print(f'Error with return code: {returncode}):\n{stderr}')


def traj2transmtx(traj, N, normalize=True):
Expand Down
72 changes: 36 additions & 36 deletions ensemble_md/analysis/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,42 @@ def cluster_traj(gmx_executable, inputs, grps, method='linkage', cutoff=0.1, suf
print(f'Inter-medoid RMSD between the two biggest clusters: {rmsd:.3f} nm')


def get_cluster_info(cluster_log):
"""
Gets the metadata of the LOG file generated by the GROMACS :code:`gmx cluster` command.
Parameters
----------
cluster_log : str
The LOG file generated by the GROMACS :code:`gmx cluster` command.
Returns
-------
rmsd_range: list
The range of RMSD values
rmsd_avg: float
The average RMSD value.
n_clusters : int
The number of clusters.
"""
f = open(cluster_log, 'r')
lines = f.readlines()
f.close()

rmsd_range = []
for line in lines:
if 'The RMSD ranges from' in line:
rmsd_range.append(float(line.split('from')[-1].split('to')[0]))
rmsd_range.append(float(line.split('from')[-1].split('to')[-1].split('nm')[0]))
if 'Average RMSD' in line:
rmsd_avg = float(line.split('is')[-1])
if 'Found' in line:
n_clusters = int(line.split()[1])
break

return rmsd_range, rmsd_avg, n_clusters


def get_cluster_members(cluster_log):
"""
Gets the members of each cluster from the LOG file generated by the GROMACS :code:`gmx cluster` command.
Expand Down Expand Up @@ -208,39 +244,3 @@ def count_transitions(clusters):
t_transitions.append(member[0])

return n_transitions, t_transitions


def get_cluster_info(cluster_log):
"""
Gets the metadata of the LOG file generated by the GROMACS :code:`gmx cluster` command.
Parameters
----------
cluster_log : str
The LOG file generated by the GROMACS :code:`gmx cluster` command.
Returns
-------
rmsd_range: list
The range of RMSD values
rmsd_avg: float
The average RMSD value.
n_clusters : int
The number of clusters.
"""
f = open(cluster_log, 'r')
lines = f.readlines()
f.close()

rmsd_range = []
for line in lines:
if 'The RMSD ranges from' in line:
rmsd_range.append(float(line.split('from')[-1].split('to')[0]))
rmsd_range.append(float(line.split('from')[-1].split('to')[-1].split('nm')[0]))
if 'Average RMSD' in line:
rmsd_avg = float(line.split('is')[-1])
if 'Found' in line:
n_clusters = int(line.split()[1])
break

return rmsd_range, rmsd_avg, n_clusters

0 comments on commit ee7d377

Please sign in to comment.