Skip to content

Commit 8a9413a

Browse files
committed
made add_back H nicer
1 parent a64bf10 commit 8a9413a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/quemb/molbe/chemfrag.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@ def add_back_H(m: Cartesian, n_BE: int, fragments: AtomPerFrag) -> AtomPerFrag:
9999
100100
If we considered only non-hydrogen atoms before, i.e. :code:`pure_heavy is True`,
101101
then add back the hydrogens."""
102+
only_H = set(m.loc[m.atom == "H", :].index)
102103
m.get_bonds(set_lookup=True)
104+
105+
def get_BE_coord_sphere(i_center: CenterIdx) -> set[AtomIdx]:
106+
return set(
107+
m.get_coordination_sphere(
108+
i_center, n_sphere=n_BE, only_surface=False, use_lookup=True
109+
).index
110+
)
111+
103112
return AtomPerFrag(
104113
{
105-
i_center: fragment_index
106-
| set(
107-
m.get_coordination_sphere(
108-
i_center, n_sphere=n_BE, only_surface=False, use_lookup=True
109-
)
110-
.loc[m.atom == "H", :]
111-
.index
112-
)
114+
i_center: fragment_index | (get_BE_coord_sphere(i_center) & only_H)
113115
for i_center, fragment_index in fragments.items()
114116
}
115117
)

0 commit comments

Comments
 (0)