Skip to content

Compare atomic number rather than symbol. #546

@k-ujihara

Description

@k-ujihara

There are a lot of codes for checking which atom IElement object is.
For example,
if (atom.getSymbol().equals("H")) { ... }
if (!(bond.getBegin().getSymbol().equals("H") && bond.getEnd().getSymbol().equals("H"))) { ... }

These can be modified like the following and which should show better performance.
if (atom.getAtomicNumber() == 1) { ... }
if (!(bond.getBegin().getAtomicNumber() == 1 && bond.getEnd().getAtomicNumber() == 1)) { ... }

In fact, current implementation of getSymbol() in org.openscience.cdk.Element.java get the symbol through Elements.ofNumber(atomicNumber) method. It is possible to implement an Element class in which getSymbol() returns "H" and getAtomicNumber() returns 5, but it is nonsense to think about such a thing.
I implemented such changes with NCDK, and it seems to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions