Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mmligner improvements #143

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions opencadd/structure/superposition/engines/mmligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ def _parse_metadata(self, output):
coverage = float(line.split()[2])
elif line.startswith("I(A & <S,T>)"):
ivalue = float(line.split()[4])
elif "Print Centers of Mass of moving set:" in line:
moving_com = np.array([float(x) for x in next(lines).split()])
elif "Print Centers of Mass of fixed set:" in line:
fixed_com = np.array([float(x) for x in next(lines).split()])
elif "Print Rotation matrix" in line:
rotation = [[float(x) for x in next(lines).split()] for _ in range(3)]
elif "Print Quaternion matrix" in line:
quaternion = [[float(x) for x in next(lines).split()] for _ in range(4)]
# elif "Print Centers of Mass of moving set:" in line:
# moving_com = np.array([float(x) for x in next(lines).split()])
# elif "Print Centers of Mass of fixed set:" in line:
# fixed_com = np.array([float(x) for x in next(lines).split()])
# elif "Print Rotation matrix" in line:
# rotation = [[float(x) for x in next(lines).split()] for _ in range(3)]
# elif "Print Quaternion matrix" in line:
# quaternion = [[float(x) for x in next(lines).split()] for _ in range(4)]
elif line.startswith("Compression"):
break

# checks if there is a signifcant alignment
if rmsd == 0 and coverage == 0:
Expand All @@ -179,7 +181,7 @@ def _parse_metadata(self, output):
# fixed_com, moving_com, rotation and quaternion can only be obtained
# if the patched mmligner is used (check /devtools/conda-recipes/mmligner)
# -- this will fail in CI for now --
translation = fixed_com - moving_com
#translation = fixed_com - moving_com

alignment = fasta.FastaFile()
alignment.read("temp__1.afasta")
Expand All @@ -188,9 +190,9 @@ def _parse_metadata(self, output):
"scores": {"rmsd": rmsd, "score": ivalue, "coverage": coverage},
"metadata": {
"alignment": alignment,
"rotation": rotation,
"translation": translation,
"quaternion": quaternion,
#"rotation": rotation,
#"translation": translation,
#"quaternion": quaternion,
},
}

Expand Down Expand Up @@ -225,6 +227,7 @@ def _parse_scoring(self, output):
"scores": {"rmsd": rmsd, "score": ivalue, "coverage": coverage},
}

# TODO: Rotation is not working correctly -> commented out for now
def _calculate_transformed(self, structures, selections, metadata):
"""
Parse back output PDBs and construct updated Structure objects.
Expand All @@ -243,16 +246,16 @@ def _calculate_transformed(self, structures, selections, metadata):
"""
ref, mobile, *_ = structures
ref_selection, mob_selection, *_ = selections
translation = metadata["translation"] # not used
rotation = metadata["rotation"]
#translation = metadata["translation"] # not used
#rotation = metadata["rotation"]

# calculation on selections
mob_com = mob_selection.atoms.center_of_geometry()
ref_com = ref_selection.atoms.center_of_geometry()

# transformation on structure
mobile.atoms.translate(-mob_com)
mobile.atoms.rotate(rotation)
#mobile.atoms.rotate(rotation)
mobile.atoms.translate(ref_com)

return ref, mobile
Expand Down