Counting the number of molecules over several SDF files

I want to read several SDF files, count the number of molecules in each file, and obtain the total number of molecules over all files.

I’ve set up a loop (as described here: http://tech.knime.org/forum/knime-users/reading-multiple-files) that does read all the desired SDF files, but I am unclear how to extract the individual molecules counts (I guess counting the rows is an option – is there a counter node?) and total them (and possibly write them to a CSV file or similar, or just view the total)

thanks for the help!

Scott

Hi Scott!

If one molecule is one row then your guess is fine - count the number of rows will do it. There are multiple ways you can count the number of rows. One is using Extract Table Dimension node.

I have created an example how you can do it. Read files using loop, count number of rows per each file, calculate total number after loop is done and write it all in csv file. Input files are in workspace directory and output will be there as well :wink:

Take a look and if any questions feel free to ask.
2019_05_15_Reading_List_of_Files_and_Counting.knwf (38.2 KB)

Br,
Ivan

Hi Ivan

it works great! thanks so much for your help.

best,

Scott

1 Like

Hi Ivan,

thanks again for your recent help. Following on this workflow, I attempted to modify it so that it would simply read all the SDFs and then write them to a single SDf file. I placed the SDF writer after the loop but it is unable to proceed. Would you happen to have thoughts on this?

thanks,

Scott

Hi Scott,

What is the output of the loop in your case? Workflow I attached calculates row count per file and writes that down to a CSV file so SDF Writer doesn’t make sense there.

If you would like to concatenate multiple SDFs into one simply after SDF Reader end your loop with Loop End which will concatenate your files if they have same structure. Try it out and if any problems I can create an example workflow.

Br,
Ivan