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

#310 Support stereo CIP calculation in Ket format #1054

Merged
merged 23 commits into from
Mar 9, 2023
Merged
41 changes: 41 additions & 0 deletions api/tests/integration/ref/basic/ketfile_stereo_desc.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
1910.mol:SUCCEED
C14_R_iso.mol:SUCCEED
C14_R_iso_2.mol:SUCCEED
CIP_issue.mol:SUCCEED
P-9.5.2.2_ex3.mol:SUCCEED
P-92.5.1.mol:SUCCEED
P-92.5.3.mol:SUCCEED
P-92.6.mol:SUCCEED
P-92.6_2.mol:SUCCEED
P-92.6_ex2.mol:SUCCEED
P-92_2_1_1_3_ex1.mol:SUCCEED
P-92_2_1_1_3_ex2.mol:SUCCEED
P-92_2_1_2_1_ex1.mol:SUCCEED
P-92_2_1_2_1_ex2.mol:SUCCEED
P-92_2_1_2_1_ex3.mol:SUCCEED
P-92_2_1_3_ex1.mol:SUCCEED
P-92_2_1_3_ex2.mol:SUCCEED
RS-symmetrical-structure.mol:SUCCEED
RS.mol:SUCCEED
RS_for_incorrect_valence.mol:SUCCEED
S-R diff.mol:SUCCEED
StereochemComplexTester_AllAbs.mol:SUCCEED
all-trans-inositol.mol:SUCCEED
atom_any.mol:SUCCEED
cis.mol:SUCCEED
different stereo 2.mol:SUCCEED
different stereo 3.mol:SUCCEED
different stereo 4.mol:SUCCEED
different stereo 5.mol:SUCCEED
different stereo.mol:SUCCEED
ketcher.mol:SUCCEED
stereo-different-ketcher-marvin.mol:SUCCEED
stereo-different-ketcher-marvin2.mol:SUCCEED
t4_R.mol:SUCCEED
t4_R_iso.mol:SUCCEED
t4_S.mol:SUCCEED
t4_S_iso.mol:SUCCEED
trans.mol:SUCCEED
without_stereo_label.mol:SUCCEED
crazystereo.rxn:SUCCEED

99 changes: 99 additions & 0 deletions api/tests/integration/tests/basic/ketfile_stereo_desc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import difflib
import os
import sys


def find_diff(a, b):
return "\n".join(difflib.unified_diff(a.splitlines(), b.splitlines()))


sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)

from env_indigo import *

threading.stack_size(2 * 1024 * 1024)


def stereo_desc_test(py_file, out_queue):
str_res = ""
ref_path = joinPathPy("ref/", __file__)
root = joinPathPy("molecules/CIP/", __file__)

indigo = Indigo()
indigo.setOption("json-saving-pretty", True)

for filename in sorted(os.listdir(root)):
ketfile = joinPathPy(
os.path.join(ref_path, filename[:-4] + ".ket"), __file__
)
mol = indigo.loadMoleculeFromFile(os.path.join(root, filename))
with open(ketfile, "r") as file:
ket_ref = file.read()
mol_json_no_cip = mol.json()
indigo.setOption("json-saving-add-stereo-desc", True)
mol_json_cip = mol.json()
diff = find_diff(ket_ref, mol_json_cip)
if not diff:
diff = find_diff(mol_json_no_cip, mol_json_cip)
indigo.setOption("json-saving-add-stereo-desc", False)
mol = indigo.loadMoleculeFromFile(
os.path.join(root, filename)
) # reload to reset CIP
if diff:
diff = find_diff(mol.json(), mol_json_no_cip)
if diff:
str_res += (
"mismatch: json-saving-add-stereo-desc = false:\n"
)
else:
# check conversion
indigo.setOption("molfile-saving-add-stereo-desc", True)
mol_cip = indigo.loadMolecule(
mol.molfile()
) # mol_cip should contain CIP as properties of atoms and bonds
diff = find_diff(
mol_cip.json(), mol_json_cip
) # check if molecule has CIP
if diff:
str_res += "mismatch: molfile loader doesn't convert CIP SGroups:\n"
else:
str_res += filename + ":SUCCEED\n"
continue
str_res += filename + ":FAILED\n"
str_res += diff + "\n"

indigo.setOption("ignore-stereochemistry-errors", "true")
filename = "crazystereo.rxn"

rxn = indigo.loadReactionFromFile(
os.path.join(joinPathPy("reactions/", __file__), filename)
)

ketfile = joinPathPy(os.path.join(ref_path, "crazystereo.ket"), __file__)
with open(ketfile, "r") as file:
ket_ref = file.read()
diff = find_diff(ket_ref, rxn.json())
if not diff:
str_res += filename + ":SUCCEED\n"
else:
str_res += filename + ":FAILED\n"
str_res += diff + "\n"
out_queue.put(str_res)


if isJython():
from Queue import Queue
else:
from queue import Queue

th_queue = Queue()
test_thread = threading.Thread(
target=stereo_desc_test, args=(os.path.abspath(__file__), th_queue)
)
test_thread.start()
test_thread.join()
print(th_queue.get())
Loading