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

#1944-Fullerene and 3D molecules are not represented as 3D in the Miew 3D window #1971

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 additions & 0 deletions api/tests/integration/ref/formats/mol_to_cdxml.py.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
*** Mol to CDXML ***
1944-3D_Structure.mol
1944-3D_Structure.mol
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CDXML SYSTEM "http://www.cambridgesoft.com/xml/cdxml.dtd">
<CDXML BondLength="30.000000" LabelFont="3" CaptionFont="4">
<fonttable id="1">
<font id="2" charset="utf-8" name="Arial"/>
<font id="3" charset="utf-8" name="Times New Roman"/>
</fonttable>
<colortable>
<color r="1" g="1" b="1"/>
<color r="0" g="0" b="0"/>
<color r="1" g="0" b="0"/>
<color r="1" g="1" b="0"/>
<color r="0" g="1" b="0"/>
<color r="0" g="1" b="1"/>
<color r="0" g="0" b="1"/>
<color r="1" g="0" b="1"/>
<color r="0.5" g="0.5" b="0.5"/>
</colortable>
<page HeightPages="1" WidthPages="1">
<fragment id="4"/>
<altgroup id="5" Valence="0">
<fragment id="6">
<n id="7" p="168.228012 294.662994" xyz="4.607600 -8.822100 -9.662200"/>
<n id="8" p="202.376999 290.210999" xyz="5.745900 -8.673700 -11.579500"/>
<n id="9" p="186.375000 273.207001" xyz="5.212500 -8.106900 -10.552700"/>
<n id="10" p="200.292007 328.707001" xyz="5.676400 -9.956900 -11.719600"/>
<n id="11" p="166.134003 333.312012" xyz="4.537800 -10.110400 -9.802900"/>
<n id="12" p="182.252991 350.123993" xyz="5.075100 -10.670800 -10.835100"/>
<b id="13" B="9" E="7" Order="2"/>
<b id="14" B="10" E="8" Order="2"/>
<b id="15" B="7" E="11"/>
<b id="16" B="8" E="9"/>
<b id="17" B="11" E="12" Order="2"/>
<b id="18" B="12" E="10"/>
</fragment>
<t p="166.134003 273.207001" InterpretChemically="no">
<s font="3" size="10" face="96">R20</s>
</t>
</altgroup>
</page>
</CDXML>

enhanced_stereo1.mol
enhanced_stereo1.mol
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/mol_to_cdxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

root = joinPathPy("molecules/", __file__)
files = [
"1944-3D_Structure.mol",
"stereo_either-0020.mol",
"enhanced_stereo1.mol",
"enhanced_stereo2.mol",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$MDL REV 1
$MOL
$HDR
null


$END HDR
$CTAB
0 0 0 0 0 0 0 0 0 0999 V2000
M END
$END CTAB
$RGP
20
$CTAB
6 6 0 0 0 0 0 0 0 0999 V2000
4.6076 -8.8221 -9.6622 C 0 0 0 0 0 0 0 0 0 0 0 0
5.7459 -8.6737 -11.5795 C 0 0 0 0 0 0 0 0 0 0 0 0
5.2125 -8.1069 -10.5527 C 0 0 0 0 0 0 0 0 0 0 0 0
5.6764 -9.9569 -11.7196 C 0 0 0 0 0 0 0 0 0 0 0 0
4.5378 -10.1104 -9.8029 C 0 0 0 0 0 0 0 0 0 0 0 0
5.0751 -10.6708 -10.8351 C 0 0 0 0 0 0 0 0 0 0 0 0
3 1 2 0 0 0
4 2 2 0 0 0
1 5 1 0 0 0
2 3 1 0 0 0
5 6 2 0 0 0
6 4 1 0 0 0
M END
$END CTAB
$END RGP
$END MOL
1 change: 1 addition & 0 deletions core/indigo-core/molecule/src/molecule_cdxml_loader.cpp
Copy link
Collaborator

@even1024 even1024 May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should be added to parseNode, not to parseText. You don't have cdxml to mol test which would reveal the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In parseNode, both p and xyz are already present. {"p", pos_lambda},{"xyz", pos_lambda},
I have made changes in parsePos to handle z coord.

Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ void MoleculeCdxmlLoader::_parseText(BaseCDXElement& elem, std::vector<std::pair
auto label_justification_alignment_lambda = [&label_alignment, this](const std::string& data) { label_alignment = data; };

std::unordered_map<std::string, std::function<void(const std::string&)>> text_dispatcher = {{"p", text_coordinates_lambda},
{"xyz", text_coordinates_lambda},
{"BoundingBox", text_bbox_lambda},
{"LabelJustification", label_justification_lambda},
{"LabelAlignment", label_justification_alignment_lambda}};
Expand Down
50 changes: 50 additions & 0 deletions core/indigo-core/molecule/src/molecule_cdxml_saver.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 copy-pastes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unnecessary copies where z coord is not required.

Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
Vec3f pos3 = mol.getAtomXyz(atom_idx);
Vec2f pos(pos3.x, pos3.y);

bool have_z = BaseMolecule::hasZCoord(mol);

pos.add(offset);
if (atom_idx == mol.vertexBegin())
min_coord = max_coord = pos;
Expand Down Expand Up @@ -680,6 +682,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
node->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
}

int enh_stereo_type = mol.stereocenters.getType(atom_idx);
Expand Down Expand Up @@ -731,6 +741,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
t->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
t->SetAttribute("Justification", "Center");

XMLElement* s = _doc->NewElement("s");
Expand All @@ -752,6 +770,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
t->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
t->SetAttribute("LabelJustification", "Left");

XMLElement* s = _doc->NewElement("s");
Expand Down Expand Up @@ -789,6 +815,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
t->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
t->SetAttribute("LabelJustification", "Left");

XMLElement* s = _doc->NewElement("s");
Expand Down Expand Up @@ -825,6 +859,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
t->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
t->SetAttribute("LabelJustification", "Left");

XMLElement* s = _doc->NewElement("s");
Expand Down Expand Up @@ -868,6 +910,14 @@ void MoleculeCdxmlSaver::addNodeToFragment(BaseMolecule& mol, XMLElement* fragme
out.printf("%f %f", pos.x, -pos.y);
buf.push(0);
t->SetAttribute("p", buf.ptr());
if (have_z)
{
QS_DEF(Array<char>, _buf);
ArrayOutput _out(_buf);
_out.printf("%f %f %f", pos3.x, pos3.y, pos3.z);
_buf.push(0);
node->SetAttribute("xyz", _buf.ptr());
}
t->SetAttribute("LabelJustification", "Left");

XMLElement* s = _doc->NewElement("s");
Expand Down
Loading