On 11/18/2013 01:32 PM, Geoffrey Hutchison wrote:
>> make an isotope/mass vector a member of OBElement instead of its "mass
>> Atomic mass (in amu)", but that's just me.)
> 
> The problem is that the full isotope table is fairly huge and rarely
used. Checking memory use, I see that in my programs, it's usually never
even initialized, while the element table obviously is.
> 
> I agree that it's perhaps not as convenient, but that's something to
consider in a backwards-incompatible Open Babel 3 effort.

The file itself is 58K, even if you get double that with the overhead, I
wouldn't call it huge even by the cellphone standards anymore...

(I calculate C13, N15, and C13+N15 mol. weights for each molecule -- I
work for NMR people -- so I use those 2 all the time.)

In the meantime, here's the patch -- feel free to rename "Prevalent" if
you can think of a better word. (All I could think of along the lines of
"NaturalAbundance" was too long for my liking.)

-- 
Dimitri Maziuk
Programmer/sysadmin
BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu
--- openbabel-2.3.2.orig/include/openbabel/data.h	2010-10-09 21:05:12.000000000 -0500
+++ openbabel-2.3.2/include/openbabel/data.h	2013-11-14 14:14:35.620535084 -0600
@@ -218,10 +218,18 @@
       size_t GetSize() { return _isotopes.size(); }
 
       void	ParseLine(const char*);
-      //! \return the exact masss of the isotope
+      //! \return the exact mass of the isotope
       //!   (or by default (i.e. "isotope 0") the most abundant isotope)
       double	GetExactMass(const unsigned int atomicNum,
                            const unsigned int isotope = 0);
+
+      //! \return the number of "natural abundance" isotope (aka isotope 0)
+      //   or 0 if there's a problem
+      unsigned int GetPrevalentIsotope( const unsigned int ele );
+
+      //! \return true if the isotope is known to exist, false otherwise (on error as well)
+      bool IsValidIsotope( const unsigned int ele, const unsigned int iso );
+
     };
 
   // class introduction in data.cpp

--- openbabel-2.3.2.orig/src/data.cpp	2012-10-03 14:08:15.000000000 -0500
+++ openbabel-2.3.2/src/data.cpp	2013-11-14 14:14:48.996570004 -0600
@@ -425,6 +425,40 @@
     return 0.0;
   }
 
+  unsigned int OBIsotopeTable::GetPrevalentIsotope( const unsigned int ele )
+  {
+    if (!_init) Init();
+    unsigned int iso = 0;
+
+    if (ele > _isotopes.size()) return iso;
+    if (_isotopes[ele].size() < 1) return iso;
+
+    double mass = _isotopes[ele][0].second;
+    for( std::vector<std::pair <unsigned int, double> >::iterator i = _isotopes[ele].begin(); i != _isotopes[ele].end(); i++ )
+        if( (i->first != 0) && (i->second == mass) ) {
+            iso = i->first;
+            break;
+        }
+    return iso;
+  }
+  
+  bool OBIsotopeTable::IsValidIsotope( const unsigned int ele, const unsigned int iso )
+  {
+    if (!_init) Init();
+
+    if( iso == 0 ) return true;
+    if (ele > _isotopes.size()) return false;
+    if (_isotopes[ele].size() < 1) return false;
+
+    bool rc = false;
+    for( std::vector<std::pair <unsigned int, double> >::iterator i = _isotopes[ele].begin(); i != _isotopes[ele].end(); i++ )
+        if( i->first == iso ) {
+            rc = true;
+            break;
+        }
+    return rc;
+  }
+
   /** \class OBTypeTable data.h <openbabel/data.h>
       \brief Atom Type Translation Table
 

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to