Logo Search packages:      
Sourcecode: cdk version File versions  Download package

void org::openscience::cdk::layout::AtomPlacer::placeLinearChain ( IAtomContainer  atomContainer,
Vector2d  initialBondVector,
double  bondLength 
) [inline]

Places the atoms in a linear chain.

Expects the first atom to be placed and places the next atom according to initialBondVector. The rest of the chain is placed such that it is as linear as possible (in the overall result, the angles in the chain are set to 120 Deg.)

Parameters:
atomContainerThe IAtomContainer containing the chain atom to be placed
initialBondVectorThe Vector indicating the direction of the first bond
bondLengthThe factor used to scale the initialBondVector

Definition at line 325 of file AtomPlacer.java.

References org::openscience::cdk::tools::LoggingTool::debug(), org::openscience::cdk::geometry::GeometryTools::get2DCenter(), org::openscience::cdk::interfaces::IAtomContainer::getAtom(), org::openscience::cdk::interfaces::IAtomContainer::getAtomCount(), org::openscience::cdk::interfaces::IAtomContainer::getBond(), org::openscience::cdk::interfaces::IChemObject::getBuilder(), org::openscience::cdk::interfaces::IAtom::getHydrogenCount(), getNextBondVector(), org::openscience::cdk::interfaces::IAtom::getPoint2d(), org::openscience::cdk::geometry::GeometryTools::has2DCoordinatesNew(), org::openscience::cdk::geometry::BondTools::isCisTrans(), org::openscience::cdk::CDKConstants::ISPLACED, org::openscience::cdk::geometry::BondTools::isValidDoubleBondConfiguration(), molecule, org::openscience::cdk::interfaces::IChemObjectBuilder::newMolecule(), org::openscience::cdk::interfaces::IChemObject::setFlag(), org::openscience::cdk::interfaces::IAtom::setHydrogenCount(), and org::openscience::cdk::interfaces::IAtom::setPoint2d().

Referenced by org::openscience::cdk::layout::StructureDiagramGenerator::generateCoordinates(), and org::openscience::cdk::layout::StructureDiagramGenerator::handleAliphatics().

    {
        IMolecule withh = atomContainer.getBuilder().newMolecule(atomContainer);

        // BUGFIX - withh does not have cloned cloned atoms, so changes are
        // reflected in our atom container. If we're using implicit hydrogens
        // the correct counts need saving and restoring
        int[] numh = new int[atomContainer.getAtomCount()];
        for (int i = 0, n = atomContainer.getAtomCount(); i < n; i ++) {
            Integer tmp = atomContainer.getAtom(i).getHydrogenCount();
            if (tmp == CDKConstants.UNSET) numh[i]= 0;
            else numh[i] = tmp;            
        }

//          SDG should lay out what it gets and not fiddle with molecules
//      during layout so this was 
//      removed during debugging. Before you put this in again, contact
//      er@doktor-steinbeck.de
        
//        if(GeometryTools.has2DCoordinatesNew(atomContainer)==2){
//            try{
//                new HydrogenAdder().addExplicitHydrogensToSatisfyValency(withh);
//            }catch(Exception ex){
//                logger.warn("Exception in hydrogen adding. This could mean that cleanup does not respect E/Z: ", ex.getMessage());
//                logger.debug(ex);
//            }
//            new HydrogenPlacer().placeHydrogens2D(withh, bondLength);
//        }
        logger.debug("Placing linear chain of length " + atomContainer.getAtomCount());
        Vector2d bondVector = initialBondVector;
        IAtom atom = null;
        Point2d atomPoint = null;
        IAtom nextAtom = null;
        for (int f = 0; f < atomContainer.getAtomCount() - 1; f++)
        {
            atom = atomContainer.getAtom(f);
            nextAtom = atomContainer.getAtom(f + 1);
            atomPoint = new Point2d(atom.getPoint2d());
            bondVector.normalize();
            bondVector.scale(bondLength);
            atomPoint.add(bondVector);
            nextAtom.setPoint2d(atomPoint);
            nextAtom.setFlag(CDKConstants.ISPLACED, true);
            boolean trans=false;
            if(GeometryTools.has2DCoordinatesNew(atomContainer)==2){
                try{
                    if(f>2 && BondTools.isValidDoubleBondConfiguration(withh,withh.getBond(withh.getAtom(f-2),withh.getAtom(f-1)))){
                        trans=BondTools.isCisTrans(withh.getAtom(f-3),withh.getAtom(f-2),withh.getAtom(f-1),withh.getAtom(f-0),withh);
                    }
                }catch(Exception ex){
                    logger.debug("Excpetion in detecting E/Z. This could mean that cleanup does not respect E/Z");
                }
                bondVector = getNextBondVector(nextAtom, atom, GeometryTools.get2DCenter(molecule),trans);
            }else{
                bondVector = getNextBondVector(nextAtom, atom, GeometryTools.get2DCenter(molecule),true);
            }
        }

        // BUGFIX part 2 - restore hydrogen counts
        for (int i = 0, n = atomContainer.getAtomCount(); i < n; i ++) {
            atomContainer.getAtom(i).setHydrogenCount(numh[i]);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index