Skip to content

Commit db81b4c

Browse files
committed
Add support for merging CMAP terms.
1 parent 5db39f1 commit db81b4c

2 files changed

Lines changed: 186 additions & 0 deletions

File tree

src/BioSimSpace/Align/_merge.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def merge(
332332
"angle",
333333
"dihedral",
334334
"improper",
335+
"cmap",
335336
"connectivity",
336337
"intrascale",
337338
]
@@ -683,6 +684,52 @@ def merge(
683684
# Add the impropers to the merged molecule.
684685
edit_mol.set_property("improper0", impropers)
685686

687+
# 5) cmap
688+
if "cmap" in shared_props:
689+
# Get the user defined property names.
690+
prop0 = inv_property_map0.get("cmap", "cmap")
691+
prop1 = inv_property_map1.get("cmap", "cmap")
692+
693+
# Get the "cmap" property from the two molecules.
694+
cmaps0 = molecule0.property(prop0)
695+
cmaps1 = molecule1.property(prop1)
696+
697+
# Get the molInfo object for each molecule.
698+
info0 = molecule0.info()
699+
info1 = molecule1.info()
700+
701+
# Create the new set of CMAP functions.
702+
cmaps = _SireMM.CMAPFunctions(edit_mol.info())
703+
704+
# Add all of the CMAP functions from molecule0.
705+
for func in cmaps0.parameters():
706+
atom0 = mol0_merged_mapping[info0.atom_idx(func.atom0())]
707+
atom1 = mol0_merged_mapping[info0.atom_idx(func.atom1())]
708+
atom2 = mol0_merged_mapping[info0.atom_idx(func.atom2())]
709+
atom3 = mol0_merged_mapping[info0.atom_idx(func.atom3())]
710+
atom4 = mol0_merged_mapping[info0.atom_idx(func.atom4())]
711+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
712+
713+
# Loop over all CMAP functions in molecule1.
714+
for func in cmaps1.parameters():
715+
# This CMAP function contains an atom that is unique to molecule1.
716+
if (
717+
info1.atom_idx(func.atom0()) in atoms1_idx
718+
or info1.atom_idx(func.atom1()) in atoms1_idx
719+
or info1.atom_idx(func.atom2()) in atoms1_idx
720+
or info1.atom_idx(func.atom3()) in atoms1_idx
721+
or info1.atom_idx(func.atom4()) in atoms1_idx
722+
):
723+
atom0 = mol1_merged_mapping[info1.atom_idx(func.atom0())]
724+
atom1 = mol1_merged_mapping[info1.atom_idx(func.atom1())]
725+
atom2 = mol1_merged_mapping[info1.atom_idx(func.atom2())]
726+
atom3 = mol1_merged_mapping[info1.atom_idx(func.atom3())]
727+
atom4 = mol1_merged_mapping[info1.atom_idx(func.atom4())]
728+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
729+
730+
# Add the CMAP functions to the merged molecule.
731+
edit_mol.set_property("cmap0", cmaps)
732+
686733
##############################
687734
# SET PROPERTIES AT LAMBDA = 1
688735
##############################
@@ -1016,6 +1063,52 @@ def merge(
10161063
# Add the impropers to the merged molecule.
10171064
edit_mol.set_property("improper1", impropers)
10181065

1066+
# 5) cmap
1067+
if "cmap" in shared_props:
1068+
# Get the user defined property names.
1069+
prop0 = inv_property_map0.get("cmap", "cmap")
1070+
prop1 = inv_property_map1.get("cmap", "cmap")
1071+
1072+
# Get the "cmap" property from the two molecules.
1073+
cmaps0 = molecule0.property(prop0)
1074+
cmaps1 = molecule1.property(prop1)
1075+
1076+
# Get the molInfo object for each molecule.
1077+
info0 = molecule0.info()
1078+
info1 = molecule1.info()
1079+
1080+
# Create the new set of CMAP functions.
1081+
cmaps = _SireMM.CMAPFunctions(edit_mol.info())
1082+
1083+
# Add all of the CMAP functions from molecule1.
1084+
for func in cmaps1.parameters():
1085+
atom0 = mol1_merged_mapping[info1.atom_idx(func.atom0())]
1086+
atom1 = mol1_merged_mapping[info1.atom_idx(func.atom1())]
1087+
atom2 = mol1_merged_mapping[info1.atom_idx(func.atom2())]
1088+
atom3 = mol1_merged_mapping[info1.atom_idx(func.atom3())]
1089+
atom4 = mol1_merged_mapping[info1.atom_idx(func.atom4())]
1090+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
1091+
1092+
# Loop over all CMAP functions in molecule0.
1093+
for func in cmaps0.parameters():
1094+
# This CMAP function contains an atom that is unique to molecule0.
1095+
if (
1096+
info0.atom_idx(func.atom0()) in atoms0_idx
1097+
or info0.atom_idx(func.atom1()) in atoms0_idx
1098+
or info0.atom_idx(func.atom2()) in atoms0_idx
1099+
or info0.atom_idx(func.atom3()) in atoms0_idx
1100+
or info0.atom_idx(func.atom4()) in atoms0_idx
1101+
):
1102+
atom0 = mol0_merged_mapping[info0.atom_idx(func.atom0())]
1103+
atom1 = mol0_merged_mapping[info0.atom_idx(func.atom1())]
1104+
atom2 = mol0_merged_mapping[info0.atom_idx(func.atom2())]
1105+
atom3 = mol0_merged_mapping[info0.atom_idx(func.atom3())]
1106+
atom4 = mol0_merged_mapping[info0.atom_idx(func.atom4())]
1107+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
1108+
1109+
# Add the CMAP functions to the merged molecule.
1110+
edit_mol.set_property("cmap1", cmaps)
1111+
10191112
# The number of potentials should be consistent for the "bond0"
10201113
# and "bond1" properties, unless a ring is broken or changes size.
10211114
if not (allow_ring_breaking or allow_ring_size_change):

src/BioSimSpace/Sandpit/Exscientia/Align/_merge.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def merge(
317317
"angle",
318318
"dihedral",
319319
"improper",
320+
"cmap",
320321
"connectivity",
321322
"intrascale",
322323
]
@@ -668,6 +669,52 @@ def merge(
668669
# Add the impropers to the merged molecule.
669670
edit_mol.set_property("improper0", impropers)
670671

672+
# 5) cmap
673+
if "cmap" in shared_props:
674+
# Get the user defined property names.
675+
prop0 = inv_property_map0.get("cmap", "cmap")
676+
prop1 = inv_property_map1.get("cmap", "cmap")
677+
678+
# Get the "cmap" property from the two molecules.
679+
cmaps0 = molecule0.property(prop0)
680+
cmaps1 = molecule1.property(prop1)
681+
682+
# Get the molInfo object for each molecule.
683+
info0 = molecule0.info()
684+
info1 = molecule1.info()
685+
686+
# Create the new set of CMAP functions.
687+
cmaps = _SireMM.CMAPFunctions(edit_mol.info())
688+
689+
# Add all of the CMAP functions from molecule0.
690+
for func in cmaps0.parameters():
691+
atom0 = mol0_merged_mapping[info0.atom_idx(func.atom0())]
692+
atom1 = mol0_merged_mapping[info0.atom_idx(func.atom1())]
693+
atom2 = mol0_merged_mapping[info0.atom_idx(func.atom2())]
694+
atom3 = mol0_merged_mapping[info0.atom_idx(func.atom3())]
695+
atom4 = mol0_merged_mapping[info0.atom_idx(func.atom4())]
696+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
697+
698+
# Loop over all CMAP functions in molecule1.
699+
for func in cmaps1.parameters():
700+
# This CMAP function contains an atom that is unique to molecule1.
701+
if (
702+
info1.atom_idx(func.atom0()) in atoms1_idx
703+
or info1.atom_idx(func.atom1()) in atoms1_idx
704+
or info1.atom_idx(func.atom2()) in atoms1_idx
705+
or info1.atom_idx(func.atom3()) in atoms1_idx
706+
or info1.atom_idx(func.atom4()) in atoms1_idx
707+
):
708+
atom0 = mol1_merged_mapping[info1.atom_idx(func.atom0())]
709+
atom1 = mol1_merged_mapping[info1.atom_idx(func.atom1())]
710+
atom2 = mol1_merged_mapping[info1.atom_idx(func.atom2())]
711+
atom3 = mol1_merged_mapping[info1.atom_idx(func.atom3())]
712+
atom4 = mol1_merged_mapping[info1.atom_idx(func.atom4())]
713+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
714+
715+
# Add the CMAP functions to the merged molecule.
716+
edit_mol.set_property("cmap0", cmaps)
717+
671718
##############################
672719
# SET PROPERTIES AT LAMBDA = 1
673720
##############################
@@ -995,6 +1042,52 @@ def merge(
9951042
# Add the impropers to the merged molecule.
9961043
edit_mol.set_property("improper1", impropers)
9971044

1045+
# 5) cmap
1046+
if "cmap" in shared_props:
1047+
# Get the user defined property names.
1048+
prop0 = inv_property_map0.get("cmap", "cmap")
1049+
prop1 = inv_property_map1.get("cmap", "cmap")
1050+
1051+
# Get the "cmap" property from the two molecules.
1052+
cmaps0 = molecule0.property(prop0)
1053+
cmaps1 = molecule1.property(prop1)
1054+
1055+
# Get the molInfo object for each molecule.
1056+
info0 = molecule0.info()
1057+
info1 = molecule1.info()
1058+
1059+
# Create the new set of CMAP functions.
1060+
cmaps = _SireMM.CMAPFunctions(edit_mol.info())
1061+
1062+
# Add all of the CMAP functions from molecule1.
1063+
for func in cmaps1.parameters():
1064+
atom0 = mol1_merged_mapping[info1.atom_idx(func.atom0())]
1065+
atom1 = mol1_merged_mapping[info1.atom_idx(func.atom1())]
1066+
atom2 = mol1_merged_mapping[info1.atom_idx(func.atom2())]
1067+
atom3 = mol1_merged_mapping[info1.atom_idx(func.atom3())]
1068+
atom4 = mol1_merged_mapping[info1.atom_idx(func.atom4())]
1069+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
1070+
1071+
# Loop over all CMAP functions in molecule0.
1072+
for func in cmaps0.parameters():
1073+
# This CMAP function contains an atom that is unique to molecule0.
1074+
if (
1075+
info0.atom_idx(func.atom0()) in atoms0_idx
1076+
or info0.atom_idx(func.atom1()) in atoms0_idx
1077+
or info0.atom_idx(func.atom2()) in atoms0_idx
1078+
or info0.atom_idx(func.atom3()) in atoms0_idx
1079+
or info0.atom_idx(func.atom4()) in atoms0_idx
1080+
):
1081+
atom0 = mol0_merged_mapping[info0.atom_idx(func.atom0())]
1082+
atom1 = mol0_merged_mapping[info0.atom_idx(func.atom1())]
1083+
atom2 = mol0_merged_mapping[info0.atom_idx(func.atom2())]
1084+
atom3 = mol0_merged_mapping[info0.atom_idx(func.atom3())]
1085+
atom4 = mol0_merged_mapping[info0.atom_idx(func.atom4())]
1086+
cmaps.set(atom0, atom1, atom2, atom3, atom4, func.parameter())
1087+
1088+
# Add the CMAP functions to the merged molecule.
1089+
edit_mol.set_property("cmap1", cmaps)
1090+
9981091
# The number of potentials should be consistent for the "bond0"
9991092
# and "bond1" properties, unless a ring is broken or changes size.
10001093
if not (allow_ring_breaking or allow_ring_size_change):

0 commit comments

Comments
 (0)