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