}
moleculeSet.addAtomContainer(atomCon);
}
// The AtomPlacer generates coordinates for the new atom
AtomPlacer atomPlacer = new AtomPlacer();
atomPlacer.setMolecule(chemModel.getBuilder().newInstance(IAtomContainer.class,atomCon));
double bondLength;
if (atomCon.getBondCount() >= 1) {
bondLength = GeometryTools.getBondLengthAverage(atomCon);
} else {
bondLength = calculateAverageBondLength(chemModel.getMoleculeSet());
}
// determine the atoms which define where the
// new atom should not be placed
List<IAtom> connectedAtoms = atomCon.getConnectedAtomsList(atom);
if (connectedAtoms.size() == 0) {
Point2d newAtomPoint = new Point2d(atom.getPoint2d());
double angle = Math.toRadians(-30);
Vector2d vec1 = new Vector2d(Math.cos(angle), Math.sin(angle));
vec1.scale(bondLength);
newAtomPoint.add(vec1);
newAtom.setPoint2d(newAtomPoint);
} else if (connectedAtoms.size() == 1) {
IAtomContainer ac = atomCon.getBuilder().newInstance(IAtomContainer.class);
ac.addAtom(atom);
ac.addAtom(newAtom);
Point2d distanceMeasure = new Point2d(0, 0); // XXX not sure about
// this?
IAtom connectedAtom = connectedAtoms.get(0);
Vector2d v = atomPlacer.getNextBondVector(atom, connectedAtom,
distanceMeasure, true);
atomPlacer.placeLinearChain(ac, v, bondLength);
} else {
IAtomContainer placedAtoms = atomCon.getBuilder().newInstance(IAtomContainer.class);
for (IAtom conAtom : connectedAtoms)
placedAtoms.addAtom(conAtom);
Point2d center2D = GeometryTools.get2DCenter(placedAtoms);
IAtomContainer unplacedAtoms = atomCon.getBuilder()
.newInstance(IAtomContainer.class);
unplacedAtoms.addAtom(newAtom);
atomPlacer.distributePartners(atom, placedAtoms, center2D,
unplacedAtoms, bondLength);
}
atomCon.addAtom(newAtom);
atomCon.addBond(newBond);