Skip to content

Commit 5af7fa9

Browse files
author
Eric Hartmann
committed
change topology object
1 parent 7358177 commit 5af7fa9

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/kimmdy/topology/atomic.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,18 @@ def from_top_line(cls, l: list[str]):
559559

560560
@dataclass()
561561
class ResidueImproperSpec:
562-
"""Information about one imroper dihedral in a residue
562+
"""Information about one improper dihedral in a residue
563563
564-
; atom1 atom2 atom3 atom4 q0 cq
564+
; atom1 atom2 atom3 atom4 c0(q0) c1(cp) c2(mult)
565565
"""
566566

567567
atom1: str
568568
atom2: str
569569
atom3: str
570570
atom4: str
571-
q0: Optional[str]
572-
cq: Optional[str]
571+
c0: Optional[str]
572+
c1: Optional[str]
573+
c2: Optional[str]
573574

574575
@classmethod
575576
def from_top_line(cls, l: list[str]):
@@ -578,23 +579,26 @@ def from_top_line(cls, l: list[str]):
578579
atom2=l[1],
579580
atom3=l[2],
580581
atom4=l[3],
581-
q0=field_or_none(l, 4),
582-
cq=field_or_none(l, 5),
582+
c0=field_or_none(l, 4),
583+
c1=field_or_none(l, 5),
584+
c2=field_or_none(l, 6),
583585
)
584586

585587

586588
@dataclass()
587589
class ResidueProperSpec:
588-
"""Information about one imroper dihedral in a residue
590+
"""Information about one proper dihedral in a residue
589591
590-
; atom1 atom2 atom3 atom4 q0 cq
592+
; atom1 atom2 atom3 atom4 c0(q0) c1(cq) c2
591593
"""
592594

593595
atom1: str
594596
atom2: str
595597
atom3: str
596598
atom4: str
597-
q0: Optional[str]
599+
c0: Optional[str]
600+
c1: Optional[str]
601+
c2: Optional[str]
598602

599603
@classmethod
600604
def from_top_line(cls, l: list[str]):
@@ -603,7 +607,9 @@ def from_top_line(cls, l: list[str]):
603607
atom2=l[1],
604608
atom3=l[2],
605609
atom4=l[3],
606-
q0=field_or_none(l, 4),
610+
c0=field_or_none(l, 4),
611+
c1=field_or_none(l, 5),
612+
c2=field_or_none(l, 6),
607613
)
608614

609615

src/kimmdy/topology/topology.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272
self.pairs: dict[tuple[str, str], Pair] = {}
7373
self.angles: dict[tuple[str, str, str], Angle] = {}
7474
self.proper_dihedrals: dict[tuple[str, str, str, str], MultipleDihedrals] = {}
75-
self.improper_dihedrals: dict[tuple[str, str, str, str], Dihedral] = {}
75+
self.improper_dihedrals: dict[tuple[str, str, str, str], MultipleDihedrals] = {}
7676
self.position_restraints: dict[str, PositionRestraint] = {}
7777
self.dihedral_restraints: dict[tuple[str, str, str, str], DihedralRestraint] = (
7878
{}
@@ -183,7 +183,11 @@ def _parse_dihedrals(self):
183183
dihedral = Dihedral.from_top_line(l)
184184
key = (dihedral.ai, dihedral.aj, dihedral.ak, dihedral.al)
185185
if dihedral.funct == "4":
186-
self.improper_dihedrals[key] = dihedral
186+
if self.improper_dihedrals.get(key) is None:
187+
self.improper_dihedrals[key] = MultipleDihedrals(
188+
*key, dihedral.funct, dihedrals={}
189+
)
190+
self.improper_dihedrals[key].dihedrals[dihedral.periodicity] = dihedral
187191
else:
188192
if self.proper_dihedrals.get(key) is None:
189193
self.proper_dihedrals[key] = MultipleDihedrals(
@@ -464,13 +468,18 @@ def _regenerate_topology_from_bound_to(self, ff):
464468
for atom in self.atoms.values():
465469
impropers = self._get_atom_improper_dihedrals(atom.nr, ff)
466470
for key, improper in impropers:
467-
self.improper_dihedrals[key] = Dihedral(
468-
improper.atom1,
469-
improper.atom2,
470-
improper.atom3,
471-
improper.atom4,
471+
self.improper_dihedrals[key] = MultipleDihedrals(
472+
*key,
472473
"4",
473-
improper.cq,
474+
dihedrals={
475+
"": Dihedral(
476+
*key,
477+
"4",
478+
c0=improper.c0,
479+
c1=improper.c1,
480+
periodicity=improper.c2,
481+
)
482+
},
474483
)
475484

476485
def reindex_atomnrs(self) -> dict[str, str]:
@@ -1256,11 +1265,12 @@ def bind_bond(
12561265
atompair_nrs[0], self.ff
12571266
) + reactive_moleculetype._get_atom_improper_dihedrals(atompair_nrs[1], self.ff)
12581267
for key, value in dihedral_k_v:
1268+
if value.c2 is None:
1269+
value.c2 = ""
12591270
if reactive_moleculetype.improper_dihedrals.get(key) is None:
1260-
# TODO: fix this
1261-
c2 = ""
1262-
if value.q0 is not None:
1263-
c2 = "1"
1264-
reactive_moleculetype.improper_dihedrals[key] = Dihedral(
1265-
key[0], key[1], key[2], key[3], "4", value.q0, value.cq, c2
1271+
reactive_moleculetype.improper_dihedrals[key] = MultipleDihedrals(
1272+
*key, "4", dihedrals={}
12661273
)
1274+
reactive_moleculetype.improper_dihedrals[key].dihedrals[value.c2] = (
1275+
Dihedral(*key, "4", c0=value.c0, c1=value.c1, periodicity=value.c2)
1276+
)

0 commit comments

Comments
 (0)