Skip to content
Snippets Groups Projects
Commit 45f0b42c authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Ensure that arbitrary compound names can be read by chemdict_tools

PDB announced they're running out of three letter codes for compounds and
switch to longer names soon. This commit ensures that OpenStructure is ready
for that switch.
parent 6aec18d7
No related branches found
No related tags found
No related merge requests found
......@@ -36,13 +36,23 @@ namespace ost { namespace conop {
namespace {
/*
COMMENT ON CREATE_CMD
CREATE_CMD specifies so called affinities. e.g. VARCHAR(64) where common sense
interprets the number 64 as max length of entries in that column.
However, sqlite 3 totally ignores this an interprets it as TEXT without any
limits. Long story short, don't worry about formulas longer than 64 characters
or longer names etc.
*/
const char* CREATE_CMD[]={
"CREATE TABLE IF NOT EXISTS chemlib_info ( "
" creation_date TIMESTAMP, "
" ost_version_used VARCHAR(64) NOT NULL);",
"CREATE TABLE IF NOT EXISTS chem_compounds ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT, "
" tlc VARCHAR(3) NOT NULL, "
" tlc VARCHAR(5) NOT NULL, "
" olc VARCHAR(1) NOT NULL, "
" dialect VARCHAR(1) NOT NULL, "
" chem_class VARCHAR(1), "
......
......@@ -9,7 +9,8 @@ set(OST_CONOP_UNIT_TESTS
if (COMPOUND_LIB)
list(APPEND OST_CONOP_UNIT_TESTS test_compound.py
test_cleanup.py)
test_cleanup.py
test_complib.py)
endif()
ost_unittest(MODULE conop
......
import unittest, os, sys
import ost
from ost import conop
import subprocess
import tempfile
class TestCompLib(unittest.TestCase):
def test_three_vs_five_letter_code(self):
prefix_path = ost.GetPrefixPath()
chemdict_tool_path = os.path.join(prefix_path, "bin", "chemdict_tool")
if not os.path.exists(chemdict_tool_path):
raise RuntimeError("Expect chemdict_tool:", chemdict_tool_path)
tmp_dir = tempfile.TemporaryDirectory()
compounds_path = os.path.join("testfiles", "test_compounds.cif")
complib_path = os.path.join(tmp_dir.name, "test_complib.dat")
cmd = [chemdict_tool_path, "create", compounds_path, complib_path]
subprocess.run(cmd)
complib = conop.CompoundLib.Load(complib_path)
comp_001 = complib.FindCompound("001")
comp_hello = complib.FindCompound("hello")
self.assertFalse(comp_001 is None)
self.assertFalse(comp_hello is None)
if __name__ == "__main__":
from ost import testutils
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print('No compound lib available. Ignoring test_complib tests.')
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment