Dear all,
    i want to understand how to add rings in the atom.In the function 
"Addring",I find the code "ringPlacer.PlaceSpiroRing" and then jump to the 
function "placeSpiroRing".And I have some problems about this function.Why do 
we have special treatment when degree==4 and numplace==2? In my understanding, 
"degree" is the number of bonds connected to sharedAtoms, and numPlaced is the 
number of other Atoms ring except sharedAtoms.
    Looking forward to your reply. Thank you!


The source code from CDK is here??
public void placeSpiroRing(IRing ring, IAtomContainer sharedAtoms, Point2d 
sharedAtomsCenter, Vector2d ringCenterVector, double bondLength) {



        IAtom startAtom = sharedAtoms.getAtom(0);
&nbsp; &nbsp; &nbsp; &nbsp; List<IBond&gt; mBonds = 
molecule.getConnectedBondsList(sharedAtoms.getAtom(0));
&nbsp; &nbsp; &nbsp; &nbsp; final int degree = mBonds.size();
&nbsp; &nbsp; &nbsp; &nbsp; logger.debug("placeSpiroRing: D=", degree);


&nbsp; &nbsp; &nbsp; &nbsp; // recalculate the ringCentreVector
&nbsp; &nbsp; &nbsp; &nbsp; if (degree != 4) {


&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int numPlaced = 0;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (IBond bond : mBonds) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IAtom nbr = 
bond.getOther(sharedAtoms.getAtom(0));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
(!nbr.getFlag(CDKConstants.ISPLACED))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numPlaced++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (numPlaced == 2) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // nudge the shared 
atom such that bond lengths will be
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // equal
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
startAtom.getPoint2d().add(ringCenterVector);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
sharedAtomsCenter.add(ringCenterVector);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double theta = Math.PI-(2 * Math.PI / 
(degree / 2));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotate(ringCenterVector, theta);
&nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; double radius = getNativeRingRadius(ring, 
bondLength);
&nbsp; &nbsp; &nbsp; &nbsp; Point2d ringCenter = new Point2d(sharedAtomsCenter);
&nbsp; &nbsp; &nbsp; &nbsp; if (degree == 4) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ringCenterVector.normalize();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ringCenterVector.scale(radius);
&nbsp; &nbsp; &nbsp; &nbsp; } else {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // spread things out a little for 
multiple spiro centres
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ringCenterVector.normalize();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ringCenterVector.scale(2*radius);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; ringCenter.add(ringCenterVector);
&nbsp; &nbsp; &nbsp; &nbsp; double addAngle = 2 * Math.PI / ring.getRingSize();


&nbsp; &nbsp; &nbsp; &nbsp; IAtom currentAtom = startAtom;
&nbsp; &nbsp; &nbsp; &nbsp; double startAngle = 
GeometryUtil.getAngle(startAtom.getPoint2d().x - ringCenter.x,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; startAtom.getPoint2d().y - ringCenter.y);


&nbsp; &nbsp; &nbsp; &nbsp; /*
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Get one bond connected to the spiro bridge 
atom. It doesn't matter in
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* which direction we draw.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp; &nbsp; &nbsp; List rBonds = ring.getConnectedBondsList(startAtom);


&nbsp; &nbsp; &nbsp; &nbsp; IBond currentBond = (IBond) rBonds.get(0);


&nbsp; &nbsp; &nbsp; &nbsp; Vector atomsToDraw = new Vector();
&nbsp; &nbsp; &nbsp; &nbsp; /*
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Store all atoms to draw in consequtive 
order relative to the chosen
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* bond.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < ring.getBondCount(); i++) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentBond = 
ring.getNextBond(currentBond, currentAtom);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentAtom = 
currentBond.getOther(currentAtom);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!currentAtom.equals(startAtom))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
atomsToDraw.addElement(currentAtom);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; logger.debug("currentAtom&nbsp; " + currentAtom);
&nbsp; &nbsp; &nbsp; &nbsp; logger.debug("startAtom&nbsp; " + startAtom);


&nbsp; &nbsp; &nbsp; &nbsp; atomPlacer.populatePolygonCorners(atomsToDraw, 
ringCenter, startAngle, addAngle, radius);


&nbsp; &nbsp; }

Attachment: RingPlacer.java
Description: Binary data

_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to