Skip to content

Commit bee6ea8

Browse files
committed
#1272 After opening a saved Extended SMILES file Single Up Bond is changed to Single Down Bond (#1273)
1 parent de85d68 commit bee6ea8

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

api/c/indigo/src/indigo_layout.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ CEXPORT int indigoLayout(int object)
5858
ml.max_iterations = self.layout_max_iterations;
5959
ml.bond_length = MoleculeLayout::DEFAULT_BOND_LENGTH;
6060
ml.layout_orientation = (layout_orientation_value)self.layout_orientation;
61+
bool has_atropisomery = mol->hasAtropisomericCenter();
62+
if (has_atropisomery)
63+
ml.respect_existing_layout = true;
6164

6265
TimeoutCancellationHandler cancellation(self.cancellation_timeout);
6366
ml.setCancellationHandler(&cancellation);
@@ -66,8 +69,8 @@ CEXPORT int indigoLayout(int object)
6669

6770
if (obj.type != IndigoObject::SUBMOLECULE)
6871
{
69-
// Not for submolecule yet
70-
mol->clearBondDirections();
72+
if (!has_atropisomery)
73+
mol->clearBondDirections();
7174
try
7275
{
7376
mol->markBondsStereocenters();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ CCCCC |Sg:n:1,2,3::hh|
7474
*** Atropisomers ***
7575
atropisomer:
7676
C1=CC=C(C)C(C2=C(N)C=C(C)C=C2)=C1O |o1:5,r,wU:5.4|
77+
C1=CC=C(C)C(C2=C(N)C=C(C)C=C2)=C1O |o1:5,r,wU:5.4|

api/tests/integration/tests/formats/smiles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@
120120
mols_smiles = ["C1C(O)=C(C2C=CC(C)=CC=2N)C(C)=CC=1 |o1:3,r,wU:3.12|"]
121121
for sm in mols_smiles:
122122
print("atropisomer:")
123-
print(indigo.loadMolecule(sm).smiles())
123+
mol = indigo.loadMolecule(sm)
124+
print(mol.smiles())
125+
mol.layout()
126+
print(mol.smiles())

core/indigo-core/layout/src/molecule_layout.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace indigo;
2626

2727
IMPL_ERROR(MoleculeLayout, "molecule_layout");
2828

29-
MoleculeLayout::MoleculeLayout(BaseMolecule& molecule, bool smart_layout) : _molecule(molecule), _smart_layout(smart_layout)
29+
MoleculeLayout::MoleculeLayout(BaseMolecule& molecule, bool smart_layout) : _molecule(molecule), _smart_layout(smart_layout), respect_existing_layout(false)
3030
{
3131
_hasMulGroups = _molecule.sgroups.getSGroupCount(SGroup::SG_TYPE_MUL) > 0;
3232
_init(smart_layout);
@@ -36,7 +36,6 @@ MoleculeLayout::MoleculeLayout(BaseMolecule& molecule, bool smart_layout) : _mol
3636
void MoleculeLayout::_init(bool smart_layout)
3737
{
3838
bond_length = 1.f;
39-
respect_existing_layout = false;
4039
filter = 0;
4140
_smart_layout = smart_layout;
4241
if (_smart_layout)

core/indigo-core/molecule/base_molecule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ namespace indigo
426426
const int* getPyramidStereocenters(int idx) const;
427427
void markBondsStereocenters();
428428
void markBondStereocenters(int atom_idx);
429+
bool hasAtropisomericCenter();
429430

430431
void addStereocenters(int atom_idx, int type, int group, const int pyramid[4]);
431432
void addStereocenters(int atom_idx, int type, int group, bool inverse_pyramid);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4196,6 +4196,17 @@ void BaseMolecule::markBondsStereocenters()
41964196
stereocenters.markBonds(*this);
41974197
}
41984198

4199+
bool BaseMolecule::hasAtropisomericCenter()
4200+
{
4201+
for (int i = stereocenters.begin(); i != stereocenters.end(); i = stereocenters.next(i))
4202+
{
4203+
auto atom_idx = stereocenters.getAtomIndex(i);
4204+
if (stereocenters.isAtropisomeric(atom_idx))
4205+
return true;
4206+
}
4207+
return false;
4208+
}
4209+
41994210
void BaseMolecule::markBondStereocenters(int atom_idx)
42004211
{
42014212
stereocenters.markBond(*this, atom_idx);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,10 +1676,11 @@ void MoleculeStereocenters::markBond(BaseMolecule& baseMolecule, int atom_idx)
16761676

16771677
void MoleculeStereocenters::markBonds(BaseMolecule& baseMolecule)
16781678
{
1679-
int i;
1680-
1681-
for (i = _stereocenters.begin(); i != _stereocenters.end(); i = _stereocenters.next(i))
1682-
markBond(baseMolecule, _stereocenters.key(i));
1679+
for (int i = _stereocenters.begin(); i != _stereocenters.end(); i = _stereocenters.next(i))
1680+
{
1681+
if (!_stereocenters.value(i).is_atropisomeric)
1682+
markBond(baseMolecule, _stereocenters.key(i));
1683+
}
16831684
}
16841685

16851686
bool MoleculeStereocenters::isAutomorphism(BaseMolecule& mol, const Array<int>& mapping, const Filter* filter)

0 commit comments

Comments
 (0)