void MoleculeInChI::_normalizeMolecule(Molecule &mol) { QS_DEF(Array<int>, ignored); ignored.clear_resize(mol.vertexEnd()); ignored.zerofill(); for (int i = mol.vertexBegin(); i < mol.vertexEnd(); i = mol.vertexNext(i)) if (mol.convertableToImplicitHydrogen(i)) ignored[i] = 1; for (int i = mol.edgeBegin(); i != mol.edgeEnd(); i = mol.edgeNext(i)) if (mol.getBondTopology(i) == TOPOLOGY_RING) mol.cis_trans.setParity(i, 0); MoleculeAutomorphismSearch of; of.detect_invalid_cistrans_bonds = true; of.detect_invalid_stereocenters = true; of.find_canonical_ordering = false; of.ignored_vertices = ignored.ptr(); of.process(mol); for (int i = mol.edgeBegin(); i != mol.edgeEnd(); i = mol.edgeNext(i)) if (mol.cis_trans.getParity(i) != 0 && of.invalidCisTransBond(i)) mol.cis_trans.setParity(i, 0); for (int i = mol.vertexBegin(); i != mol.vertexEnd(); i = mol.vertexNext(i)) if (mol.stereocenters.getType(i) > MoleculeStereocenters::ATOM_ANY && of.invalidStereocenter(i)) mol.stereocenters.remove(i); }
void CmfSaver::_encodeBond (Molecule &mol, int idx, const int *mapping) { int order = mol.getBondOrder(idx); if (order == BOND_SINGLE) { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_SINGLE_RING); else _encode(CMF_BOND_SINGLE_CHAIN); } else if (order == BOND_DOUBLE) { int parity = mol.cis_trans.getParity(idx); if (parity != 0) { int mapped_parity = MoleculeCisTrans::applyMapping(parity, mol.cis_trans.getSubstituents(idx), mapping, true); if (mapped_parity == MoleculeCisTrans::CIS) { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_DOUBLE_RING_CIS); else _encode(CMF_BOND_DOUBLE_CHAIN_CIS); } else // mapped_parity == MoleculeCisTrans::TRANS { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_DOUBLE_RING_TRANS); else _encode(CMF_BOND_DOUBLE_CHAIN_TRANS); } } else if (mol.cis_trans.isIgnored(idx)) { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_DOUBLE_IGNORED_CIS_TRANS_RING); else _encode(CMF_BOND_DOUBLE_IGNORED_CIS_TRANS_CHAIN); } else { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_DOUBLE_RING); else _encode(CMF_BOND_DOUBLE_CHAIN); } } else if (order == BOND_TRIPLE) { if (mol.getBondTopology(idx) == TOPOLOGY_RING) _encode(CMF_BOND_TRIPLE_RING); else _encode(CMF_BOND_TRIPLE_CHAIN); } else if (order == BOND_AROMATIC) _encode(CMF_BOND_AROMATIC); else throw Error("bad bond order: %d", order); if (bond_flags != 0) { int i, flags = bond_flags[idx]; for (i = 0; i < CMF_NUM_OF_BOND_FLAGS; i++) if (flags & (1 << i)) _encode(CMF_BOND_FLAGS + i); } if (save_highlighting) if (mol.isBondHighlighted(idx)) _encode(CMF_HIGHLIGHTED); }