Skip to content

Commit ea381c0

Browse files
committed
filtering matrices to avoid zero eigenvalues
1 parent 0ac02af commit ea381c0

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

CodeEntropy/entropy.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def execute(self):
9292
states_ua = {}
9393
states_res = [None for _ in range(number_molecules)]
9494

95+
# Looping over timesteps to build the covariance matrices
9596
for timestep in reduced_atom.trajectory[start:end:step]:
9697
time_index = timestep.frame - start
9798

@@ -161,22 +162,6 @@ def execute(self):
161162

162163
bin_width = self._args.bin_width
163164

164-
force_matrix_ua = {k: v / number_frames for k, v in force_matrix_ua.items()}
165-
torque_matrix_ua = {k: v / number_frames for k, v in torque_matrix_ua.items()}
166-
167-
force_matrix_res = [
168-
f / number_frames if f is not None else None for f in force_matrix_res
169-
]
170-
torque_matrix_res = [
171-
t / number_frames if t is not None else None for t in torque_matrix_res
172-
]
173-
force_matrix_poly = [
174-
f / number_frames if f is not None else None for f in force_matrix_poly
175-
]
176-
torque_matrix_poly = [
177-
t / number_frames if t is not None else None for t in torque_matrix_poly
178-
]
179-
180165
# Do the entropy calculations
181166
for molecule_id in range(number_molecules):
182167
mol_container = self._get_molecule_container(reduced_atom, molecule_id)
@@ -378,11 +363,19 @@ def _process_united_atom_entropy(
378363

379364
key = (mol_id, residue_id)
380365

366+
f_matrix = force_matrix[key]
367+
f_matrix = self._level_manager.filter_zero_rows_columns(f_matrix)
368+
f_matrix = f_matrix / number_frames
369+
370+
t_matrix = torque_matrix[key]
371+
t_matrix = self._level_manager.filter_zero_rows_columns(t_matrix)
372+
t_matrix = t_matrix / number_frames
373+
381374
S_trans_res = ve.vibrational_entropy_calculation(
382-
force_matrix[key], "force", self._args.temperature, highest
375+
f_matrix, "force", self._args.temperature, highest
383376
)
384377
S_rot_res = ve.vibrational_entropy_calculation(
385-
torque_matrix[key], "torque", self._args.temperature, highest
378+
t_matrix, "torque", self._args.temperature, highest
386379
)
387380

388381
S_conf_res = ce.conformational_entropy_calculation(
@@ -429,7 +422,11 @@ def _process_vibrational_entropy(
429422
highest (bool): Flag indicating if this is the highest granularity
430423
level.
431424
"""
432-
425+
number_frames = len(mol_container.trajectory)
426+
force_matrix = self._level_manager.filter_zero_rows_columns(force_matrix)
427+
force_matrix = force_matrix / number_frames
428+
torque_matrix = self._level_manager.filter_zero_rows_columns(torque_matrix)
429+
torque_matrix = torque_matrix / number_frames
433430
S_trans = ve.vibrational_entropy_calculation(
434431
force_matrix, "force", self._args.temperature, highest
435432
)

0 commit comments

Comments
 (0)