Skip to content

Commit e496671

Browse files
committed
adding force halving
1 parent 7611b3f commit e496671

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

CodeEntropy/GeometricFunctions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def get_sphCoord_axes(arg_r):
200200
return spherical_basis
201201
# END
202202

203-
def get_weighted_forces(data_container, bead, trans_axes):
203+
def get_weighted_forces(data_container, bead, trans_axes, highest_level, force_partitioning=0.5):
204204
"""
205205
Function to calculate the mass weighted forces for a given bead.
206206
@@ -222,6 +222,12 @@ def get_weighted_forces(data_container, bead, trans_axes):
222222
forces_local = nmp.matmul(trans_axes, data_container.atoms[atom.index].force)
223223
forces_trans += forces_local
224224

225+
if highest_level:
226+
# multiply by the force_partitioning parameter to avoid double counting
227+
# of the forces on weakly correlated atoms
228+
# the default value of force_partitioning is 0.5 (dividing by two)
229+
forces_trans = force_partitioning * forces_trans
230+
225231
# divide the sum of forces by the mass of the bead to get the weighted forces
226232
mass = bead.total_mass()
227233

@@ -230,7 +236,7 @@ def get_weighted_forces(data_container, bead, trans_axes):
230236
return weighted_force
231237
#END
232238

233-
def get_weighted_torques(data_container, bead, rot_axes):
239+
def get_weighted_torques(data_container, bead, rot_axes, force_partitioning=0.5):
234240
"""
235241
Function to calculate the moment of inertia weighted torques for a given bead.
236242
@@ -256,6 +262,11 @@ def get_weighted_torques(data_container, bead, rot_axes):
256262
# update local forces in rotational frame
257263
forces_rot = nmp.matmul(rot_axes, data_container.atoms[atom.index].force)
258264

265+
# multiply by the force_partitioning parameter to avoid double counting
266+
# of the forces on weakly correlated atoms
267+
# the default value of force_partitioning is 0.5 (dividing by two)
268+
forces_rot = force_partitioning * forces_rot
269+
259270
# define torques (cross product of coordinates and forces) in rotational axes
260271
torques_local = nmp.cross(coords_rot, forces_rot)
261272
torques += torques_local

CodeEntropy/LevelFunctions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def select_levels(data_container, verbose):
4545
return number_molecules, levels
4646
#END get_levels
4747

48-
def get_matrices(data_container, level, verbose, start, end, step, number_frames):
48+
def get_matrices(data_container, level, verbose, start, end, step, number_frames, highest_level):
4949
"""
5050
Function to create the force matrix needed for the transvibrational entropy calculation
5151
and the torque matrix for the rovibrational entropy calculation.
@@ -84,7 +84,7 @@ def get_matrices(data_container, level, verbose, start, end, step, number_frames
8484
trans_axes, rot_axes = GF.get_axes(data_container, level, bead_index)
8585

8686
## Sort out coordinates, forces, and torques for each atom in the bead
87-
weighted_forces[bead_index][timestep.frame] = GF.get_weighted_forces(data_container, list_of_beads[bead_index], trans_axes)
87+
weighted_forces[bead_index][timestep.frame] = GF.get_weighted_forces(data_container, list_of_beads[bead_index], trans_axes, highest_level)
8888
weighted_torques[bead_index][timestep.frame] = GF.get_weighted_torques(data_container, list_of_beads[bead_index], rot_axes)
8989

9090
## Make covariance matrices - looping over pairs of beads

CodeEntropy/main_mcc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import math
12
import MDAnalysis as mda
23
import numpy as nmp
34
import pandas as pd
45
from CodeEntropy import LevelFunctions as LF
56
from CodeEntropy import EntropyFunctions as EF
67
from CodeEntropy import MDAUniverseHelper as MDAHelper
7-
from CodeEntropy import poseidon
88

99
def main(arg_dict):
1010
"""
@@ -23,13 +23,13 @@ def main(arg_dict):
2323

2424
# Define trajectory slicing from inputs
2525
start = arg_dict['start']
26-
if start == None:
26+
if start is None:
2727
start = 0
2828
end = arg_dict['end']
29-
if end == None:
29+
if end is None:
3030
end = -1
3131
step = arg_dict['step']
32-
if step == None:
32+
if step is None:
3333
step = 1
3434
# Count number of frames, easy if not slicing
3535
if start == 0 and end == -1 and step == 1:
@@ -100,7 +100,7 @@ def main(arg_dict):
100100

101101
## Vibrational entropy at every level
102102
# Get the force and torque matrices for the beads at the relevant level
103-
force_matrix, torque_matrix = LF.get_matrices(residue_container, level, arg_dict['verbose'], start, end, step, number_frames)
103+
force_matrix, torque_matrix = LF.get_matrices(residue_container, level, arg_dict['verbose'], start, end, step, number_frames, highest_level)
104104

105105
# Calculate the entropy from the diagonalisation of the matrices
106106
S_trans_residue = EF.vibrational_entropy(force_matrix, "force", arg_dict['temper'],highest_level)
@@ -177,7 +177,7 @@ def main(arg_dict):
177177
if level in ('polymer', 'residue'):
178178
## Vibrational entropy at every level
179179
# Get the force and torque matrices for the beads at the relevant level
180-
force_matrix, torque_matrix = LF.get_matrices(molecule_container, level, arg_dict['verbose'], start, end, step, number_frames)
180+
force_matrix, torque_matrix = LF.get_matrices(molecule_container, level, arg_dict['verbose'], start, end, step, number_frames, highest_level)
181181

182182
# Calculate the entropy from the diagonalisation of the matrices
183183
S_trans = EF.vibrational_entropy(force_matrix, "force", arg_dict['temper'],highest_level)

0 commit comments

Comments
 (0)