Quantcast

Proposal to overhaul/replace OBElementTable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Proposal to overhaul/replace OBElementTable

Noel O'Boyle
Administrator
Hi there,

The OBElementTable has some problems, and I propose a replacement.
Conversion of element numbers to symbols and vice versa is one of the
operations that should be optimal in a cheminf toolkit but is not
currently. Here's what I propose:

1. No global etab is necessary, just a collection of namespaced
functions, e.g. OBElement::GetAtomicNum(). There's no need for a class
to store state, as the state will be compiled in.
2. The GetAtomicNum() will be a compiled prefix tree using switch
statements. Right now, if you ask what is the atomic number of Fermium
(element 100), it will do 100 string comparisons.
3. The GetSymbol() will be a array lookup returning compiled-in const
char*. It'll be a whisker more efficient than the current code.
4. We can add an enum for atomic symbols, in anticipation (perhaps) of
removing OBAtom::IsCarbon() and friends in place of
OBAtom::GetAtomicNum() == OBElem:Carbon

The current OBElementTable can be implemented in terms of these new
functions, but ideally it would be deprecated or better still removed.

Regards,
- Noel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-Devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Proposal to overhaul/replace OBElementTable

Geoff Hutchison
> 2. The GetAtomicNum() will be a compiled prefix tree using switch
> statements. Right now, if you ask what is the atomic number of Fermium
> (element 100), it will do 100 string comparisons.

Fair enough - does it make sense to hand-write the switch statements, though?

> 4. We can add an enum for atomic symbols, in anticipation (perhaps) of
> removing OBAtom::IsCarbon() and friends in place of
> OBAtom::GetAtomicNum() == OBElem:Carbon

This sounds like a nice idea.

-Geoff

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-Devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Proposal to overhaul/replace OBElementTable

David Hall
On Sat, Feb 25, 2017 at 6:06 PM, Geoffrey Hutchison <[hidden email]> wrote:
> 2. The GetAtomicNum() will be a compiled prefix tree using switch
> statements. Right now, if you ask what is the atomic number of Fermium
> (element 100), it will do 100 string comparisons.

Fair enough - does it make sense to hand-write the switch statements, though?


My suggestion would be to use gperf

https://www.gnu.org/software/gperf/

I have cmake run gperf for me as part of my builds. It has been at least a year since I did a build on Windows though, so I don't recall whether it was annoying to get it working there.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-Devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Proposal to overhaul/replace OBElementTable

Noel O'Boyle
Administrator
In reply to this post by Geoff Hutchison
These days I've got a Python script that generates switch statements.

On 25 Feb 2017 11:06 p.m., "Geoffrey Hutchison" <[hidden email]> wrote:
> 2. The GetAtomicNum() will be a compiled prefix tree using switch
> statements. Right now, if you ask what is the atomic number of Fermium
> (element 100), it will do 100 string comparisons.

Fair enough - does it make sense to hand-write the switch statements, though?

> 4. We can add an enum for atomic symbols, in anticipation (perhaps) of
> removing OBAtom::IsCarbon() and friends in place of
> OBAtom::GetAtomicNum() == OBElem:Carbon

This sounds like a nice idea.

-Geoff

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-Devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel
Loading...