Skip to content

LargestPiSystemDescriptor visited flags and minor code improvements#1218

Merged
johnmay merged 1 commit intocdk:mainfrom
JonasSchaub:LargestPiSystemDescriptor-visited-fix
Sep 1, 2025
Merged

LargestPiSystemDescriptor visited flags and minor code improvements#1218
johnmay merged 1 commit intocdk:mainfrom
JonasSchaub:LargestPiSystemDescriptor-visited-fix

Conversation

@JonasSchaub
Copy link
Copy Markdown
Contributor

Makes LargestPiSystemDescriptor use an internal "visited" array instead of the IChemObject flag VISITED of the atoms for safe parallelisation over shared molecule instances.
Also, minor code improvements in exception handling and un-commented debug messages (and added a logger to the class, first of all).

… of IChemObject flag VISITED for safe parallelisation
@johnmay
Copy link
Copy Markdown
Member

johnmay commented Sep 1, 2025

Looks ok but I really would not share a molecule in a parallel environment. So much of the rest of the toolkit depends on this not being the case and it's just useful to draw the line there. If you want to work on something in multiple thread makes a copy but mostly you should only really need parallelism for large sets of molecules. Any method which is too slow on a single molecule on modern hardware is likely not a useful method.

for (Object bond : bonds) {
nextAtom = ((IBond) bond).getOther(atom);
logger.debug("BreadthFirstSearch around atom " + (container.indexOf(atom) + 1));
List<IBond> bonds = container.getConnectedBondsList(atom);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now safely use for (IBond bond : atom.bonds())

|| nextAtom.getAtomicNumber() == IElement.N || nextAtom.getAtomicNumber() == IElement.O)
& !nextAtom.getFlag(IChemObject.VISITED)) {
//logger.debug("BDS> AtomNr:"+container.indexOf(nextAtom)+" maxBondOrder:"+container.getMaximumBondOrder(nextAtom)+" Aromatic:"+nextAtom.getFlag(CDKConstants.ISAROMATIC)+" FormalCharge:"+nextAtom.getFormalCharge()+" Charge:"+nextAtom.getCharge()+" Flag:"+nextAtom.getFlag(CDKConstants.VISITED));
&& !visited[container.indexOf(nextAtom)]) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextAtom.getIndex()

}
} else {
nextAtom.setFlag(IChemObject.VISITED, true);
visited[container.indexOf(nextAtom)] = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextAtom.getIndex()

@johnmay johnmay merged commit 2b80f90 into cdk:main Sep 1, 2025
6 of 7 checks passed
@JonasSchaub JonasSchaub deleted the LargestPiSystemDescriptor-visited-fix branch September 1, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants