I have a quick question regarding creating a custom node that is able to read atomic coordinates, e. g. from an SdfCell object. I need the coordinates for some additional calculations inside the node. At the end an additional column with a number should appear, in which the result of the coordinate calculation is contained.
I took a look at the examples and some comments in the forum and the setup of the node seems pretty straight-forward. However I seem to cannot find how to extract the atomic coordinates out of the SdfCell in order to perform my calculations.
Could you parse the CTAB from the SdfCell to extract the coordinates?
I expect one of the chemical engines could extract the coordinates. CDK may have a method like atom.getCoordinates() and you could iterate over the atoms int molecule?
You may also be able to do this with ChemAxon, I expect the API features you need would be covered under the API.
I expected to find this functionality within the org.knime.chem.* or similar namespaces without the need to turn to third party packages. Since the molecules are drawn in the table in the UI dialog, there should be a method for getting the atoms.
I haven't tried your ChemAxon way, but I found out, that I can convert the molecules to CDK and then use CDKNodeUtils.calculateCoordinates(). However this seems a bit of an overhead and I was hoping that there is a more elegant way of doing this without an aditional library.
Any further suggestions would be much appreciated!
I don't believe any of the core KNIME provides anything more than the types. So you are unlikely to find any structure manipulation functionality there. (or am I mistaken?)
The rendering of the structures is drawn by one of the third party (partner/community) plugins you have installed.
does calculateCoordinates generate the coordinates and overwrite those given?
yepp, that might very well be the case, that a third party plugin is rendering those and I looked and found nothing, so I guess you are right.
It seems that calculateCoordinates generates new 2D coordinates but doesn't overwrite the old ones, if not forced. So it is not what I need anyway. With the CDK what is needed is indeed only this :
IAtomContainer cdkMol = SilentChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
IteratingSDFReader reader = new IteratingSDFReader(new StringReader(referenceMoleculeCell.getStringValue()), SilentChemObjectBuilder.getInstance());
while (reader.hasNext())
{
cdkMol.add(reader.next());
}
I'm currently looking into your ChemAxon example which seems equivalent. Thank you for providing me with those insights. You have been very helpful.
If you just need to access the co-ordinates, may be as easy in a java snippet to do something like this:
String[] sdfLines = sdfcell.split("\n");
int nAtoms = Integer.parseInt(sdfLines[3].split(" ")[0].trim()); //Check the 3 - it is the counts line in the sdf header block - it might be 2!
Double[] x = new Double[nAtoms];
Double[] y = new Double[nAtoms];
Double[] z = new Double[nAtoms];
for (int i = 4; i<nAtoms+4; i++) {
//Loop through the atom lines to get the co-ords
//Instead of putting all into arrays, you could use iteratively in your
//Calculation if amenable
x[i-4]=Double.parseDouble(sdfLines.substring(0,10).trim());
y[i-4]=Double.parseDouble(sdfLines.substring(10,20).trim());
z[i-4]=Double.parseDouble(sdfLines.substring(20,30).trim());
}
//Now do your stuff with the co-ords