Thanks for your reply.
I want to implement a JChemPaint in C#. In fact, I used a CDK port, named NCDK 
which is C# impementation implementation of the Chemistry Development 
Kit.  https://github.com/kazuyaujihara/NCDK. 
But I have got some bugs. I want to read the source code of CDK and fix it.
The bug is like this:
When we addRing, we need to calculate the position of the virtual ring. From 
the code , I understand that the position of the new ring need to be calculated 
by some variables, include the new ring center, startAngle, addAngle, radius.
The code in function "placeSpiroRing" is 
atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, 
addAngle, radius);The variable ringCenter is dependent on the variable 
ringCenterVector which is a vector pointing the the center of the new ring. 


For example, when I want to add a triangle to a shared atom, It satisfies 
numplace==2.It seems that the sharedAtom' s position will be changed.

The code in function "placeSpiroRing" is 

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

And when degree == 4 and degree != 4, ringCenterVector is differently 
recalculate. Why? 
The code in function "placeSpiroRing" is 
if (degree == 4) {            
ringCenterVector.normalize();
            ringCenterVector.scale(radius);
        } else {
            // spread things out a little for 
multiple spiro centres
            ringCenterVector.normalize();
            ringCenterVector.scale(2*radius);
        }

I'm confused. Or I understand it wrong.


Thank you for taking your time to read this letter again.


------------------ ???????? ------------------
??????:&nbsp;"Christoph Steinbeck"<christoph.steinb...@uni-jena.de&gt;;
????????:&nbsp;2019??11??18??(??????) ????6:55
??????:&nbsp;"????????"<843982...@qq.com&gt;;
????:&nbsp;"cdk-user"<cdk-user@lists.sourceforge.net&gt;;
????:&nbsp;Re: [Cdk-user] Questions about the function "Addring"



Can you comment on what you try to achieve?
The method that you are referring to is a quite specialised method for 
structure diagram layout. 
Are you trying to create 2D drawings of some molecule or fragment, or maybe 
something else?

Kind regards, &nbsp; Chris

?? 
Prof. Dr. Christoph Steinbeck
Analytical Chemistry - Cheminformatics and Chemometrics
Friedrich-Schiller-University Jena, Germany
Phone Secretariat: +49-3641-948171
http://cheminf.uni-jena.de
http://orcid.org/0000-0001-6966-0814

What is man but that lofty spirit - that sense of enterprise.
... Kirk, "I, Mudd," stardate 4513.3..

&gt; On 18. Nov 2019, at 11:32, ???????? <843982...@qq.com&gt; wrote:
&gt; 
&gt; Dear all,
&gt;&nbsp;&nbsp; &nbsp; 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.
&gt;&nbsp;&nbsp; &nbsp; Looking forward to your reply. Thank you!
&gt; 
&gt; The source code from CDK is here??
&gt; public void placeSpiroRing(IRing ring, IAtomContainer sharedAtoms, Point2d 
sharedAtomsCenter, Vector2d ringCenterVector, double bondLength) {
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; IAtom startAtom = 
sharedAtoms.getAtom(0);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; List<IBond&gt; mBonds = 
molecule.getConnectedBondsList(sharedAtoms.getAtom(0));
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; final int degree = 
mBonds.size();
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; logger.debug("placeSpiroRing: 
D=", degree);
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // recalculate the 
ringCentreVector
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (degree != 4) {
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; int 
numPlaced = 0;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for 
(IBond bond : mBonds) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; IAtom nbr = bond.getOther(sharedAtoms.getAtom(0));
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; if (!nbr.getFlag(CDKConstants.ISPLACED))
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; continue;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; numPlaced++;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if 
(numPlaced == 2) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; // nudge the shared atom such that bond lengths will be
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; // equal
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; startAtom.getPoint2d().add(ringCenterVector);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; sharedAtomsCenter.add(ringCenterVector);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; double 
theta = Math.PI-(2 * Math.PI / (degree / 2));
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
rotate(ringCenterVector, theta);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; double radius = 
getNativeRingRadius(ring, bondLength);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Point2d ringCenter = new 
Point2d(sharedAtomsCenter);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (degree == 4) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
ringCenterVector.normalize();
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
ringCenterVector.scale(radius);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; } else {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // 
spread things out a little for multiple spiro centres
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
ringCenterVector.normalize();
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
ringCenterVector.scale(2*radius);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
ringCenter.add(ringCenterVector);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; double addAngle = 2 * Math.PI / 
ring.getRingSize();
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; IAtom currentAtom = startAtom;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; double startAngle = 
GeometryUtil.getAngle(startAtom.getPoint2d().x - ringCenter.x,
&gt;&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;&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);
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; /*
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; * Get one bond connected 
to the spiro bridge atom. It doesn't matter in
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; * which direction we draw.
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; */
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; List rBonds = 
ring.getConnectedBondsList(startAtom);
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; IBond currentBond = (IBond) 
rBonds.get(0);
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Vector atomsToDraw = new 
Vector();
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; /*
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; * Store all atoms to draw 
in consequtive order relative to the chosen
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; * bond.
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; */
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for (int i = 0; i < 
ring.getBondCount(); i++) {
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
currentBond = ring.getNextBond(currentBond, currentAtom);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
currentAtom = currentBond.getOther(currentAtom);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if 
(!currentAtom.equals(startAtom))
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; atomsToDraw.addElement(currentAtom);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; logger.debug("currentAtom&nbsp; 
" + currentAtom);
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; logger.debug("startAtom&nbsp; " 
+ startAtom);
&gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, 
addAngle, radius);
&gt; 
&gt;&nbsp;&nbsp; &nbsp; }

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

Reply via email to