@@ -39,7 +39,7 @@ def get_beads(data_container, level):
3939def get_axes (data_container , level , index = 0 ):
4040 """
4141 Function to set the translational and rotational axes.
42- The translational axes are based on the principal axes of the unit one level larger than
42+ The translational axes are based on the rotational axes of the unit one level larger than
4343 the level we are interested in (except for the polymer level where there is no larger unit).
4444 The rotational axes use the covalent links between residues or atoms where possible to
4545 define the axes, or if the unit is not bonded to others of the same level the prinicpal
@@ -93,22 +93,46 @@ def get_axes(data_container, level, index=0):
9393
9494 if level == "united_atom" :
9595 ## Translation
96- # for united atoms use principal axes of residue for translation
97- trans_axes = data_container .residues .principal_axes ()
96+ # The translational axes for the united atom level should be the same as the rotational axes of the residue level.
97+ index_prev = index - 1
98+ index_next = index + 1
99+ atom_set = data_container .select_atoms (f"(resindex { index_prev } or resindex { index_next } ) and bonded resid { index } " )
100+ residue = data_container .select_atoms (f"resindex { index } " )
101+
102+ if len (atom_set ) == 0 :
103+ # if no bonds to other residues use pricipal axes of residue
104+ trans_axes = residue .atoms .principal_axes ()
105+
106+ else :
107+ # set center of rotation to center of mass of the residue
108+ center = residue .atoms .center_of_mass ()
109+
110+ # get vector for average position of bonded atoms
111+ vector = get_avg_pos (atom_set , center )
112+
113+ # use spherical coordinates function to get rotational axes
114+ trans_axes = get_sphCoord_axes (vector )
98115
99116 ## Rotation
100117 # for united atoms use heavy atoms bonded to the heavy atom
101118 atom_set = data_container .select_atoms (f"not name H* and bonded index { index } " )
102119
103- # center at position of heavy atom
104- atom_group = data_container .select_atoms (f"index { index } " )
105- center = atom_group .positions [0 ]
120+ if len (atom_set ) == 0 :
121+ # if no bonds to other heavy atoms use pricipal axes of residue
122+ # this is the case where there is only one united atom in the residue, so the principal axes of the residue are the same as the principal axes of the united atom
123+ # NOTE if you have argon or helium that is spherically symmetric you use random axes, but we should check that the prinicipal_axes function does that and doesn't cause an error when the residue/united atom has only one atom.
124+ trans_axes = residue .atoms .principal_axes ()
125+
126+ else :
127+ # center at position of heavy atom
128+ atom_group = data_container .select_atoms (f"index { index } " )
129+ center = atom_group .positions [0 ]
106130
107- # get vector for average position of hydrogens
108- vector = get_avg_pos (atom_set , center )
131+ # get vector for average position of hydrogens
132+ vector = get_avg_pos (atom_set , center )
109133
110- # use spherical coordinates function to get rotational axes
111- rot_axes = get_sphCoord_axes (vector )
134+ # use spherical coordinates function to get rotational axes
135+ rot_axes = get_sphCoord_axes (vector )
112136
113137 return trans_axes , rot_axes
114138# END
0 commit comments