static void renumber(Graph g) { int maxMapIdx = 0; for (int i = 0; i < g.order(); i++) maxMapIdx = Math.max(maxMapIdx, g.atom(i).atomClass()); if (maxMapIdx == 0) return; State state = new State(g, maxMapIdx); for (int i = 0; i < g.order(); i++) if (!state.visit[i]) traverse(state, i); } }
/** * Create a new CDK {@link IAtom} from the Beam Atom. * * @param beamAtom an Atom from the Beam ChemicalGraph * @param hCount hydrogen count for the atom * @return the CDK atom to have it's properties set */ IAtom toCDKAtom(Atom beamAtom, int hCount) { IAtom cdkAtom = newCDKAtom(beamAtom); cdkAtom.setImplicitHydrogenCount(hCount); cdkAtom.setFormalCharge(beamAtom.charge()); if (beamAtom.isotope() >= 0) cdkAtom.setMassNumber(beamAtom.isotope()); if (beamAtom.aromatic()) cdkAtom.setIsAromatic(true); if (beamAtom.atomClass() > 0) cdkAtom.setProperty(ATOM_ATOM_MAPPING, beamAtom.atomClass()); return cdkAtom; }
private static void traverse(State s, int idx) { s.visit[idx] = true; int mapIdx = s.g.atom(idx).atomClass(); if (mapIdx != 0) { if (s.map[mapIdx] == 0) s.map[mapIdx] = ++s.nMaps; mapIdx = s.map[mapIdx]; s.g.setAtom(idx, AtomBuilder.fromExisting(s.g.atom(idx)).atomClass(mapIdx).build()); } for (Edge e : s.g.edges(idx)) { int nbr = e.other(idx); if (!s.visit[nbr]) traverse(s, nbr); } }
static Atom toSubset(Atom a, Graph g, int u) { // atom is already a subset atom if (a.subset()) return a; // element is not organic and thus cannot be part of the subset if (!a.element().organic()) return a; // if any of these values are set the atom cannot be a subset atom if (a.charge() != 0 || a.atomClass() != 0 || a.isotope() >= 0) return a; Atom subset = a.aromatic() ? AtomImpl.AromaticSubset.ofElement(a.element()) : AtomImpl.AliphaticSubset.ofElement(a.element()); // does the implied availableElectrons from the bond order sum match that // which was stored - if aromatic we only check the lowest valence state int impliedHCount = subset.hydrogens(g, u); // mismatch in number of hydrogens we must write this as a bracket atom return impliedHCount != a.hydrogens() ? a : subset; } }