Skip to content

Commit 081b6a7

Browse files
authored
#2722 Monomer could be saved to RDF V3000 format but can't be loaded back - exception (#2876)
1 parent 2233f9a commit 081b6a7

7 files changed

Lines changed: 83 additions & 5 deletions

File tree

api/tests/integration/ref/formats/pathway.py.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ pathway9.rdf:SUCCEED
1010
pathway10.rdf:SUCCEED
1111
pathway11.rdf:SUCCEED
1212
pathway12.rdf:SUCCEED
13+
pathway_mon.rdf:SUCCEED

api/tests/integration/tests/formats/pathway.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def find_diff(a, b):
3131
"pathway10",
3232
"pathway11",
3333
"pathway12",
34+
"pathway_mon",
3435
]
3536

3637
for filename in files:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$RDFILE 1
2+
$DATM 04/25/25 10:02
3+
$RFMT
4+
$RXN V3000
5+
6+
-INDIGO- 0425251002
7+
8+
M V30 COUNTS 1 0
9+
M V30 BEGIN REACTANT
10+
M V30 BEGIN CTAB
11+
M V30 COUNTS 1 0 0 0 0
12+
M V30 BEGIN ATOM
13+
M V30 1 A 10.2 -7.775 0.0 0 CLASS=AA SEQID=1
14+
M V30 END ATOM
15+
M V30 BEGIN BOND
16+
M V30 END BOND
17+
M V30 END CTAB
18+
M V30 BEGIN TEMPLATE
19+
M V30 TEMPLATE 1 AA/Ala/A/ NATREPLACE=AA/A
20+
M V30 BEGIN CTAB
21+
M V30 COUNTS 7 6 3 0 0
22+
M V30 BEGIN ATOM
23+
M V30 1 N -0.866 -0.25 0.0 0
24+
M V30 2 C 0.0 0.25 0.0 0 CFG=2
25+
M V30 3 H -1.732 0.25 0.0 0
26+
M V30 4 C 0.866 -0.25 0.0 0
27+
M V30 5 O 1.732 0.25 0.0 0
28+
M V30 6 O 0.866 -1.25 0.0 0
29+
M V30 7 C 0.0 1.25 0.0 0
30+
M V30 END ATOM
31+
M V30 BEGIN BOND
32+
M V30 1 1 1 2
33+
M V30 2 1 1 3
34+
M V30 3 1 2 4
35+
M V30 4 1 4 5
36+
M V30 5 2 4 6
37+
M V30 6 1 2 7 CFG=1
38+
M V30 END BOND
39+
M V30 BEGIN COLLECTION
40+
M V30 MDLV30/STEABS ATOMS=(1 2)
41+
M V30 END COLLECTION
42+
M V30 BEGIN SGROUP
43+
M V30 1 SUP 1 ATOMS=(1 3) XBONDS=(1 2) BRKXYZ=(9 0.433000 -0.250000 0.000000-
44+
M V30 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000) LABEL=H CLASS=-
45+
M V30 LGRP
46+
M V30 2 SUP 2 ATOMS=(1 5) XBONDS=(1 4) BRKXYZ=(9 -0.433000 -0.250000 0.00000-
47+
M V30 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000) LABEL=OH CLAS-
48+
M V30 S=LGRP
49+
M V30 3 SUP 3 ATOMS=(5 1 2 4 6 7) XBONDS=(2 2 4) BRKXYZ=(9 -0.433000 0.25000-
50+
M V30 0 0.000000 0.433000 0.250000 0.000000 0.000000 0.000000 0.000000) LABE-
51+
M V30 L=A CLASS=AA SAP=(3 1 3 Al) SAP=(3 4 5 Br) NATREPLACE=AA/A
52+
M V30 END SGROUP
53+
M V30 END CTAB
54+
M V30 END TEMPLATE
55+
M V30 END REACTANT
56+
M V30 BEGIN PRODUCT
57+
M V30 END PRODUCT
58+
M END
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"root":{"nodes":[{"type":"arrow","data":{"mode":"filled-triangle","pos":[{"x":2.694444417953491,"y":-2.0,"z":0.0},{"x":9.69444465637207,"y":-2.0,"z":0.0}]}},{"$ref":"monomer0"}],"connections":[],"templates":[{"$ref":"monomerTemplate-Ala_1"}]},"monomer0":{"type":"monomer","id":"0","seqid":1,"position":{"x":1.0,"y":-2.0},"alias":"A","templateId":"Ala_1"},"monomerTemplate-Ala_1":{"type":"monomerTemplate","id":"Ala_1","class":"AminoAcid","classHELM":"PEPTIDE","alias":"A","name":"Ala","naturalAnalogShort":"A","naturalAnalog":"Ala","attachmentPoints":[{"attachmentAtom":0,"leavingGroup":{"atoms":[2]}},{"attachmentAtom":3,"leavingGroup":{"atoms":[4]}}],"atoms":[{"label":"N","location":[-0.8659999966621399,-0.25,0.0]},{"label":"C","location":[0.0,0.25,0.0],"stereoLabel":"abs"},{"label":"H","location":[-1.7319999933242798,0.25,0.0]},{"label":"C","location":[0.8659999966621399,-0.25,0.0]},{"label":"O","location":[1.7319999933242798,0.25,0.0]},{"label":"O","location":[0.8659999966621399,-1.25,0.0]},{"label":"C","location":[0.0,1.25,0.0]}],"bonds":[{"type":1,"atoms":[0,1]},{"type":1,"atoms":[0,2]},{"type":1,"atoms":[1,3]},{"type":1,"atoms":[3,4]},{"type":2,"atoms":[3,5]},{"type":1,"atoms":[1,6],"stereo":1}]}}

core/indigo-core/molecule/inchi_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace indigo
6060

6161
void parseInchiOutput(const InchiOutput& inchi_output, Molecule& mol);
6262

63-
void generateInchiInput(Molecule& mol, inchi_Input& input, Array<inchi_Atom>& atoms, Array<inchi_Stereo0D>& stereo);
63+
void generateInchiInput(Molecule& input_mol, inchi_Input& input, Array<inchi_Atom>& atoms, Array<inchi_Stereo0D>& stereo);
6464

6565
void neutralizeV5Nitrogen(Molecule& mol);
6666

core/indigo-core/molecule/src/inchi_wrapper.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,16 @@ void InchiWrapper::parseInchiOutput(const InchiOutput& inchi_output, Molecule& m
404404
}
405405
}
406406

407-
void InchiWrapper::generateInchiInput(Molecule& mol, inchi_Input& input, Array<inchi_Atom>& atoms, Array<inchi_Stereo0D>& stereo)
407+
void InchiWrapper::generateInchiInput(Molecule& input_mol, inchi_Input& input, Array<inchi_Atom>& atoms, Array<inchi_Stereo0D>& stereo)
408408
{
409+
Molecule tmol;
410+
auto tcount = input_mol.tgroups.getTGroupCount();
411+
Molecule& mol = tcount ? tmol : input_mol;
412+
if (tcount)
413+
{
414+
tmol.clone_KeepIndices(input_mol);
415+
tmol.transformSCSRtoFullCTAB();
416+
}
409417
QS_DEF(Array<int>, mapping);
410418
mapping.clear_resize(mol.vertexEnd());
411419
mapping.fffill();
@@ -425,7 +433,8 @@ void InchiWrapper::generateInchiInput(Molecule& mol, inchi_Input& input, Array<i
425433
throw Error("Molecule with pseudoatom (%s) cannot be converted into InChI", mol.getPseudoAtom(v));
426434
if (atom_number == ELEM_RSITE)
427435
throw Error("Molecule with RGroups cannot be converted into InChI");
428-
strncpy(atom.elname, Element::toString(atom_number), ATOM_EL_LEN);
436+
437+
strncpy(atom.elname, atom_number == ELEM_TEMPLATE ? mol.getTemplateAtom(v) : Element::toString(atom_number), ATOM_EL_LEN);
429438

430439
Vec3f& c = mol.getAtomXyz(v);
431440
atom.x = c.x;
@@ -471,7 +480,14 @@ void InchiWrapper::generateInchiInput(Molecule& mol, inchi_Input& input, Array<i
471480

472481
// Other properties
473482
atom.isotopic_mass = mol.getAtomIsotope(v);
474-
atom.radical = mol.getAtomRadical(v);
483+
try
484+
{
485+
atom.radical = mol.getAtomRadical(v);
486+
}
487+
catch (Molecule::Error&)
488+
{
489+
atom.radical = 0;
490+
}
475491
atom.charge = mol.getAtomCharge(v);
476492

477493
// Hydrogens

core/indigo-core/molecule/src/molecule_tgroups.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ int MoleculeTGroups::findTGroup(const char* name)
208208
TGroup& tgroup = *_tgroups.at(i);
209209
if (tgroup.tgroup_name.size() > 0 && name != 0)
210210
{
211-
if (strncmp(tgroup.tgroup_name.ptr(), name, tgroup.tgroup_name.size()) == 0)
211+
if (strncmp(tgroup.tgroup_name.ptr(), name, tgroup.tgroup_name.size()) == 0 ||
212+
strncmp(tgroup.tgroup_alias.ptr(), name, tgroup.tgroup_alias.size()) == 0)
212213
return i;
213214
}
214215
}

0 commit comments

Comments
 (0)