.getRelevantAtomContainer(chemModel, atom);
IAtomContainer sharedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
sharedAtoms.addAtom(atom);
// make a benzene ring
IRing newRing = createAttachRing(sharedAtoms, 6, "C", phantom);
newRing.getBond(0).setOrder(IBond.Order.DOUBLE);
newRing.getBond(2).setOrder(IBond.Order.DOUBLE);
newRing.getBond(4).setOrder(IBond.Order.DOUBLE);
double bondLength;
if (sourceContainer.getBondCount() == 0) {
/*
* Special case of adding a ring to a single, unconnected atom -
* places the ring centered on the place where the atom was.
*/
bondLength = calculateAverageBondLength(chemModel.getMoleculeSet());
Point2d ringCenter = new Point2d(atom.getPoint2d());
ringPlacer.placeRing(newRing, ringCenter, bondLength,
RingPlacer.jcpAngles);
} else {
bondLength = GeometryTools.getBondLengthAverage(sourceContainer);
Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms,
chemModel);
Point2d sharedAtomsCenter = atom.getPoint2d();
Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter);
ringCenterVector.sub(conAtomsCenter);
if ((ringCenterVector.x == 0 && ringCenterVector.y == 0)) {
return chemModel.getBuilder().newInstance(IRing.class);
} else {
ringPlacer.placeSpiroRing(newRing, sharedAtoms,
sharedAtomsCenter, ringCenterVector, bondLength);
}
}
// add the ring to the source container/phantoms
for (IAtom ringAtom : newRing.atoms()) {
if (ringAtom != atom) {
if (phantom)
this.addPhantomAtom(ringAtom);
else
sourceContainer.addAtom(ringAtom);
}
}
for (IBond ringBond : newRing.bonds()) {
if (phantom)
this.addPhantomBond(ringBond);
else
sourceContainer.addBond(ringBond);
}
if (!phantom)
updateAtoms(sourceContainer, newRing.atoms());
for (IAtom newatom : newRing.atoms()) {
if (atom != newatom && getClosestAtom(atom) != null) {
JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
double d = rModel.getHighlightDistance() / rModel.getScale();
atom.getPoint2d().x += d;
}