From ee7d37701503bbaf37c612d372763f5c676d8129 Mon Sep 17 00:00:00 2001 From: Wei-Tse Hsu Date: Sun, 20 Aug 2023 17:34:25 -0600 Subject: [PATCH] Tweaked analyze_traj.py and clustering.py --- ensemble_md/analysis/analyze_traj.py | 4 +- ensemble_md/analysis/clustering.py | 72 ++++++++++++++-------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/ensemble_md/analysis/analyze_traj.py b/ensemble_md/analysis/analyze_traj.py index f92331fd..385febf6 100644 --- a/ensemble_md/analysis/analyze_traj.py +++ b/ensemble_md/analysis/analyze_traj.py @@ -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): diff --git a/ensemble_md/analysis/clustering.py b/ensemble_md/analysis/clustering.py index 98d456ed..4a2cda2f 100644 --- a/ensemble_md/analysis/clustering.py +++ b/ensemble_md/analysis/clustering.py @@ -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. @@ -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