* org.openscience.cdk.controller.IChemModelRelay#addAtomWithoutUndo(java
* .lang.String, org.openscience.cdk.interfaces.IAtom, int)
*/
public IAtom addAtomWithoutUndo(String atomType, IAtom atom,
IBond.Stereo stereo, Order order, boolean makePseudoAtom) {
IAtom newAtom;
if (makePseudoAtom) {
newAtom = chemModel.getBuilder().newInstance(IPseudoAtom.class,atomType);
} else {
newAtom = chemModel.getBuilder().newInstance(IAtom.class,atomType);
}
IBond newBond;
if (order == IBond.Order.DOUBLE) {
newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
CDKConstants.BONDORDER_DOUBLE, stereo);
} else if (order == IBond.Order.TRIPLE) {
newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
CDKConstants.BONDORDER_TRIPLE, stereo);
} else {
newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
CDKConstants.BONDORDER_SINGLE, stereo);
}
IAtomContainer atomCon = ChemModelManipulator.getRelevantAtomContainer(
chemModel, atom);
if (atomCon == null) {
atomCon = chemModel.getBuilder().newInstance(IAtomContainer.class);
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
if (moleculeSet == null) {
moleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
chemModel.setMoleculeSet(moleculeSet);
}
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);