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.
------------------ ???????? ------------------
??????: "Christoph Steinbeck"<christoph.steinb...@uni-jena.de>;
????????: 2019??11??18??(??????) ????6:55
??????: "????????"<843982...@qq.com>;
????: "cdk-user"<cdk-user@lists.sourceforge.net>;
????: 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, 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..
> On 18. Nov 2019, at 11:32, ???????? <843982...@qq.com> wrote:
>
> 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);
> List<IBond> mBonds =
molecule.getConnectedBondsList(sharedAtoms.getAtom(0));
> final int degree =
mBonds.size();
> logger.debug("placeSpiroRing:
D=", degree);
>
> // recalculate the
ringCentreVector
> if (degree != 4) {
>
> int
numPlaced = 0;
> for
(IBond bond : mBonds) {
>
IAtom nbr = bond.getOther(sharedAtoms.getAtom(0));
>
if (!nbr.getFlag(CDKConstants.ISPLACED))
>
continue;
>
numPlaced++;
> }
>
> if
(numPlaced == 2) {
>
// nudge the shared atom such that bond lengths will be
>
// equal
>
startAtom.getPoint2d().add(ringCenterVector);
>
sharedAtomsCenter.add(ringCenterVector);
> }
>
> double
theta = Math.PI-(2 * Math.PI / (degree / 2));
>
rotate(ringCenterVector, theta);
> }
>
> double radius =
getNativeRingRadius(ring, bondLength);
> Point2d ringCenter = new
Point2d(sharedAtomsCenter);
> if (degree == 4) {
>
ringCenterVector.normalize();
>
ringCenterVector.scale(radius);
> } else {
> //
spread things out a little for multiple spiro centres
>
ringCenterVector.normalize();
>
ringCenterVector.scale(2*radius);
> }
>
ringCenter.add(ringCenterVector);
> double addAngle = 2 * Math.PI /
ring.getRingSize();
>
> IAtom currentAtom = startAtom;
> double startAngle =
GeometryUtil.getAngle(startAtom.getPoint2d().x - ringCenter.x,
>
startAtom.getPoint2d().y - ringCenter.y);
>
> /*
> * Get one bond connected
to the spiro bridge atom. It doesn't matter in
> * which direction we draw.
> */
> List rBonds =
ring.getConnectedBondsList(startAtom);
>
> IBond currentBond = (IBond)
rBonds.get(0);
>
> Vector atomsToDraw = new
Vector();
> /*
> * Store all atoms to draw
in consequtive order relative to the chosen
> * bond.
> */
> for (int i = 0; i <
ring.getBondCount(); i++) {
>
currentBond = ring.getNextBond(currentBond, currentAtom);
>
currentAtom = currentBond.getOther(currentAtom);
> if
(!currentAtom.equals(startAtom))
>
atomsToDraw.addElement(currentAtom);
> }
> logger.debug("currentAtom
" + currentAtom);
> logger.debug("startAtom "
+ startAtom);
>
>
atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle,
addAngle, radius);
>
> }
> _______________________________________________
> Cdk-user mailing list
> Cdk-user@lists.sourceforge.net
> 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