Skip to content

Commit 0418f8b

Browse files
authored
Merge pull request #267 from CCPBioSim/UArovib-fix
Align CodeEntropy with entropy methods used in 2019 paper
2 parents 75d3f96 + d4f5924 commit 0418f8b

File tree

10 files changed

+2511
-342
lines changed

10 files changed

+2511
-342
lines changed

CodeEntropy/axes.py

Lines changed: 507 additions & 0 deletions
Large diffs are not rendered by default.

CodeEntropy/config/arg_config_manager.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@
8585
"help": "How to group molecules for averaging",
8686
"default": "molecules",
8787
},
88+
"combined_forcetorque": {
89+
"type": bool,
90+
"help": """Use combined force-torque matrix for residue
91+
level vibrational entropies""",
92+
"default": True,
93+
},
94+
"customised_axes": {
95+
"type": bool,
96+
"help": """Use bonded axes to rotate forces for UA
97+
level vibrational entropies""",
98+
"default": True,
99+
},
88100
}
89101

90102

CodeEntropy/entropy.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def execute(self):
122122
else:
123123
nonwater_groups.update(water_groups)
124124

125-
force_matrices, torque_matrices, frame_counts = (
125+
force_matrices, torque_matrices, forcetorque_matrices, frame_counts = (
126126
self._level_manager.build_covariance_matrices(
127127
self,
128128
reduced_atom,
@@ -133,6 +133,8 @@ def execute(self):
133133
step,
134134
number_frames,
135135
self._args.force_partitioning,
136+
self._args.combined_forcetorque,
137+
self._args.customised_axes,
136138
)
137139
)
138140

@@ -155,6 +157,7 @@ def execute(self):
155157
nonwater_groups,
156158
force_matrices,
157159
torque_matrices,
160+
forcetorque_matrices,
158161
states_ua,
159162
states_res,
160163
frame_counts,
@@ -230,6 +233,7 @@ def _compute_entropies(
230233
groups,
231234
force_matrices,
232235
torque_matrices,
236+
forcetorque_matrices,
233237
states_ua,
234238
states_res,
235239
frame_counts,
@@ -309,6 +313,7 @@ def _compute_entropies(
309313
f"Level: {level}",
310314
)
311315
highest = level == levels[groups[group_id][0]][-1]
316+
forcetorque_matrix = None
312317

313318
if level == "united_atom":
314319
self._process_united_atom_entropy(
@@ -326,6 +331,8 @@ def _compute_entropies(
326331
)
327332

328333
elif level == "residue":
334+
if highest:
335+
forcetorque_matrix = forcetorque_matrices["res"][group_id]
329336
self._process_vibrational_entropy(
330337
group_id,
331338
mol,
@@ -334,6 +341,7 @@ def _compute_entropies(
334341
level,
335342
force_matrices["res"][group_id],
336343
torque_matrices["res"][group_id],
344+
forcetorque_matrix,
337345
highest,
338346
)
339347

@@ -347,6 +355,8 @@ def _compute_entropies(
347355
)
348356

349357
elif level == "polymer":
358+
if highest:
359+
forcetorque_matrix = forcetorque_matrices["poly"][group_id]
350360
self._process_vibrational_entropy(
351361
group_id,
352362
mol,
@@ -355,6 +365,7 @@ def _compute_entropies(
355365
level,
356366
force_matrices["poly"][group_id],
357367
torque_matrices["poly"][group_id],
368+
forcetorque_matrix,
358369
highest,
359370
)
360371

@@ -530,6 +541,7 @@ def _process_vibrational_entropy(
530541
level,
531542
force_matrix,
532543
torque_matrix,
544+
forcetorque_matrix,
533545
highest,
534546
):
535547
"""
@@ -548,21 +560,43 @@ def _process_vibrational_entropy(
548560
# Find the relevant force and torque matrices and tidy them up
549561
# by removing rows and columns that are all zeros
550562

551-
force_matrix = self._level_manager.filter_zero_rows_columns(force_matrix)
563+
if forcetorque_matrix is not None:
564+
forcetorque_matrix = self._level_manager.filter_zero_rows_columns(
565+
forcetorque_matrix
566+
)
552567

553-
torque_matrix = self._level_manager.filter_zero_rows_columns(torque_matrix)
568+
S_FTtrans = ve.vibrational_entropy_calculation(
569+
forcetorque_matrix, "forcetorqueTRANS", self._args.temperature, highest
570+
)
571+
S_FTrot = ve.vibrational_entropy_calculation(
572+
forcetorque_matrix, "forcetorqueROT", self._args.temperature, highest
573+
)
554574

555-
# Calculate the vibrational entropy
556-
S_trans = ve.vibrational_entropy_calculation(
557-
force_matrix, "force", self._args.temperature, highest
558-
)
559-
S_rot = ve.vibrational_entropy_calculation(
560-
torque_matrix, "torque", self._args.temperature, highest
561-
)
575+
self._data_logger.add_results_data(
576+
group_id, level, "FTmat-Transvibrational", S_FTtrans
577+
)
578+
self._data_logger.add_results_data(
579+
group_id, level, "FTmat-Rovibrational", S_FTrot
580+
)
562581

563-
# Print the vibrational entropy for the molecule group
564-
self._data_logger.add_results_data(group_id, level, "Transvibrational", S_trans)
565-
self._data_logger.add_results_data(group_id, level, "Rovibrational", S_rot)
582+
else:
583+
force_matrix = self._level_manager.filter_zero_rows_columns(force_matrix)
584+
585+
torque_matrix = self._level_manager.filter_zero_rows_columns(torque_matrix)
586+
587+
# Calculate the vibrational entropy
588+
S_trans = ve.vibrational_entropy_calculation(
589+
force_matrix, "force", self._args.temperature, highest
590+
)
591+
S_rot = ve.vibrational_entropy_calculation(
592+
torque_matrix, "torque", self._args.temperature, highest
593+
)
594+
595+
# Print the vibrational entropy for the molecule group
596+
self._data_logger.add_results_data(
597+
group_id, level, "Transvibrational", S_trans
598+
)
599+
self._data_logger.add_results_data(group_id, level, "Rovibrational", S_rot)
566600

567601
residue_group = "_".join(
568602
sorted(set(res.resname for res in mol_container.residues))
@@ -899,6 +933,7 @@ def vibrational_entropy_calculation(self, matrix, matrix_type, temp, highest_lev
899933
"""
900934
# N beads at a level => 3N x 3N covariance matrix => 3N eigenvalues
901935
# Get eigenvalues of the given matrix and change units to SI units
936+
logger.debug(f"matrix_type: {matrix_type}")
902937
lambdas = la.eigvals(matrix)
903938
logger.debug(f"Eigenvalues (lambdas) before unit change: {lambdas}")
904939

@@ -939,6 +974,11 @@ def vibrational_entropy_calculation(self, matrix, matrix_type, temp, highest_lev
939974
else:
940975
S_vib_total = sum(S_components[6:])
941976

977+
elif matrix_type == "forcetorqueTRANS": # three lowest are translations
978+
S_vib_total = sum(S_components[:3])
979+
elif matrix_type == "forcetorqueROT": # three highest are rotations
980+
S_vib_total = sum(S_components[3:])
981+
942982
else: # torque covariance matrix - we always take all values into account
943983
S_vib_total = sum(S_components)
944984

0 commit comments

Comments
 (0)