Skip to content

Commit a6d7047

Browse files
authored
Merge pull request #167 from CCPBioSim/166-light-atoms
Change Light Atom Selection Criteria From Name To Mass
2 parents 47685f4 + 3b0a6d5 commit a6d7047

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

CodeEntropy/levels.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def select_levels(self, data_container):
6262
"united_atom"
6363
) # every molecule has at least one atom
6464

65-
atoms_in_fragment = fragments[molecule].select_atoms("not name H*")
65+
atoms_in_fragment = fragments[molecule].select_atoms("prop mass > 1.1")
6666
number_residues = len(atoms_in_fragment.residues)
6767

6868
if len(atoms_in_fragment) > 1:
@@ -337,19 +337,23 @@ def get_beads(self, data_container, level):
337337
atom_group = "resindex " + str(residue)
338338
list_of_beads.append(data_container.select_atoms(atom_group))
339339

340-
# NOTE this could cause problems for hydrogen or helium molecules
341340
if level == "united_atom":
342341
list_of_beads = []
343-
heavy_atoms = data_container.select_atoms("not name H*")
344-
for atom in heavy_atoms:
345-
atom_group = (
346-
"index "
347-
+ str(atom.index)
348-
+ " or (name H* and bonded index "
349-
+ str(atom.index)
350-
+ ")"
351-
)
352-
list_of_beads.append(data_container.select_atoms(atom_group))
342+
heavy_atoms = data_container.select_atoms("prop mass > 1.1")
343+
if len(heavy_atoms) == 0:
344+
# molecule without heavy atoms would be a hydrogen molecule
345+
list_of_beads.append(data_container.select_atoms("all"))
346+
else:
347+
# Select one heavy atom and all light atoms bonded to it
348+
for atom in heavy_atoms:
349+
atom_group = (
350+
"index "
351+
+ str(atom.index)
352+
+ " or ((prop mass <= 1.1) and bonded index "
353+
+ str(atom.index)
354+
+ ")"
355+
)
356+
list_of_beads.append(data_container.select_atoms(atom_group))
353357

354358
logger.debug(f"List of beads: {list_of_beads}")
355359

@@ -421,7 +425,7 @@ def get_axes(self, data_container, level, index=0):
421425
# Rotation
422426
# for united atoms use heavy atoms bonded to the heavy atom
423427
atom_set = data_container.select_atoms(
424-
f"not name H* and bonded index {index}"
428+
f"(prop mass > 1.1) and bonded index {index}"
425429
)
426430

427431
if len(atom_set) == 0:
@@ -432,7 +436,7 @@ def get_axes(self, data_container, level, index=0):
432436
atom_group = data_container.select_atoms(f"index {index}")
433437
center = atom_group.positions[0]
434438

435-
# get vector for average position of hydrogens
439+
# get vector for average position of bonded atoms
436440
vector = self.get_avg_pos(atom_set, center)
437441

438442
# use spherical coordinates function to get rotational axes
@@ -1125,7 +1129,7 @@ def build_conformational_states(
11251129
)
11261130
heavy_res = (
11271131
entropy_manager._run_manager.new_U_select_atom(
1128-
res_container, "not name H*"
1132+
res_container, "prop mass > 1.1"
11291133
)
11301134
)
11311135
states = self.compute_dihedral_conformations(

tests/test_CodeEntropy/test_levels.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ def test_get_beads_united_atom_level(self):
421421
data_container.select_atoms.call_count, 4
422422
) # 1 for heavy_atoms + 3 beads
423423

424+
def test_get_beads_hydrogen_molecule(self):
425+
"""
426+
Test `get_beads` for 'united_atom' level.
427+
Should return one bead for molecule with no heavy atoms.
428+
"""
429+
level_manager = LevelManager()
430+
431+
data_container = MagicMock()
432+
heavy_atoms = []
433+
data_container.select_atoms.side_effect = [
434+
heavy_atoms,
435+
"hydrogen",
436+
]
437+
438+
result = level_manager.get_beads(data_container, level="united_atom")
439+
440+
self.assertEqual(len(result), 1)
441+
self.assertEqual(result, ["hydrogen"])
442+
self.assertEqual(
443+
data_container.select_atoms.call_count, 2
444+
) # 1 for heavy_atoms + 1 beads
445+
424446
def test_get_axes_united_atom_no_bonds(self):
425447
"""
426448
Test `get_axes` for 'united_atom' level when no bonded atoms are found.

0 commit comments

Comments
 (0)