## File: element.h

package info (click to toggle)
gnome-chemistry-utils 0.14.9-1
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 // -*- C++ -*- /* * Gnome Chemistry Utils * element.h * * Copyright (C) 2002-2012 Jean Bréfort * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 * USA */ #ifndef GCU_ELEMENT_H #define GCU_ELEMENT_H #include #include #include #include "chemistry.h" #include "isotope.h" #include "value.h" #include "macros.h" /*!\file */ /*!\def GCU_ERROR Defines a standard error value. */ #define GCU_ERROR (1 << (sizeof(int) - 1)) /*!\namespace gcu \brief The Gnome Chemistry Utils C++ classes The namespace used for all C++ classes provided by the Gnome Chemistry Utils base library. */ namespace gcu { class EltTable; /*!\class Element gcu/element.h @brief Chemical element. Represents a chemical element. This class has no public constructor or destructor. The instances are created by the framework from data in the elements.xml file and a user cannot create a new element. */ class Element { friend class EltTable; private: /*! \param Z: the atomic number corresponding to the element \param Symbol: the atomic symbol of the element This constructor is private and cannot be used ouside of this class. */ Element (int Z, const char* Symbol); /*! The destructor. */ virtual ~Element (); public: /*! @param Z: the atomic number of a chemical element. @return The chemical symbol of the element whose atomic number is Z or NULL if the element is unknown. */ static const char* Symbol (int Z); /*! @param Z: the atomic number of a chemical element. This static method is used to know on what side of the symbol of the element whose atomic number is Z attached hydrogens should be written. @return true if hydrogens should be written on the right and false when it should be written on the left side. */ static bool BestSide (int Z); /*! @param symbol: the symbol of a chemical element. @return The atomic number of the element whose chemical symbol is used as parameter or 0 if the element is unknown. */ static int Z (const char* symbol); /*! @param Z: the atomic number of a chemical element. @return a pointer to the Element whose atomic number is Z or NULL if the element is unknown. */ static Element* GetElement (int Z); /*! @param symbol: the symbol of a chemical element. @return a pointer to the Element whose symbol is used as parameter or NULL if the element is unknown. */ static Element* GetElement (const char* symbol); /*! @param radius: a pointer to a GcuAtomicRadius structure. Before calling this function, most fields in the GcuAtomicRadius structure must be filled: - Z: the atomic number, mandatory - type: the type of the radius searched - charge: the charge of the atom. 0 for all radii except ionic radii. - cn: the coordination number or -1 if not significant - spin: the spin state or GCU_N_A_SPIN if not significant - scale: the name of the scale (e.g. "Pauling") or NULL The programs searches a value corresponding to the fields having a non default value. If one is found the other fields are given the corresponding values f the first match before returning. @return true if a radius has been found and false if not. */ static bool GetRadius (GcuAtomicRadius* radius); /*! @param en: a pointer to a GcuElectronegativity structure. Before calling this function, the following fields in the GcuElectronegativity structure must be filled: - Z: the atomic number, mandatory - type: the gcu_radius_type, mandatory - charge: the charge of the atom, mandatory; must be 0 for non ionic radii and non null for ionic radii. - scale: the name of the scale (e.g. "Pauling") or NULL The programs searches an electronegativity value for the element in the scale if given. If one is found the value and the scale (if NULL on calling) are given the corresponding values of the first match before returning. @return true if a match has been found and false if not. */ static bool GetElectronegativity (GcuElectronegativity* en); /*! @param Z: the atomic number of a chemical element. The value returned by this method might be too low in some cases and is only indicative. Instances of the Atom class accept any number of bonds. This behavior might change in future versions. @return the maximum number of bonds an atom of the element can be involved in. */ static unsigned GetMaxBonds (int Z); /*! Loads the atomic radii database. */ static void LoadRadii (); /*! Loads the atomic electronic properties database. */ static void LoadElectronicProps (); /*! Loads the isotopes database. */ static void LoadIsotopes (); /*! Loads the Blue Obelisk Database. */ static void LoadBODR (); /*! Loads all databases. */ static void LoadAllData (); /*! Intialize the element database. There is no need to call this method if any of the Load*() method is called. */ static void Init (); /*! \return The atomic number of the chemical element. */ int GetZ () {return m_Z;} /*! \return The chemical symbol of the element. */ const char* GetSymbol () {return m_Symbol;} /*! \return The default valence of the element for some elements, mainly non metals. For others, the returned value is -1 and should not be taken into account. */ char GetDefaultValence () {return m_DefaultValence;} /*! The value returned by this method might be too low in some cases and is only indicative. Instances of the Atom class accept any number of bonds. This behavior might change in future versions. @return the maximum number of bonds an atom of the element can be involved in. */ unsigned GetMaxBonds () {return m_MaxBonds;} /*! This static method is used to know on what side of the symbol of the element attached hydrogens should be written. @return true if hydrogens should be written on the right and false when it should be written on the left side. */ bool GetBestSide () {return m_BestSide;} /*! Retrieves the default color used for the element. @return an array of three double values for the red, green and blue components of the color. */ double* GetDefaultColor () {return m_DefaultColor;} /*! @return the name of the element in the current locale or in english if the current locale is not supported in the database. */ const char* GetName () {return name.c_str();} /*! @return a pointer to the array of pointers to GcuAtomicRadius structures for all known radii for the element. Last value in the array is NULL. */ const GcuAtomicRadius** GetRadii (); /*! @return a pointer to the array of pointers to GcuElectronegativity structures for all known electronegativities for the element. Last value in the array is NULL. */ const GcuElectronegativity** GetElectronegativities (); /*! @return the number of valence electrons of the neutral atom. */ unsigned GetValenceElectrons () {return m_nve;} /*! @return the number of valence electrons of the neutral atom, including d and f electrons. */ unsigned GetTotalValenceElectrons () {return m_tve;} /*! @return the maximume number of valence electrons of the neutral atom, including d and f electrons. */ unsigned GetMaxValenceElectrons () {return m_maxve;} /*! @return the atomic molar mass of the element. */ DimensionalValue const *GetWeight (); /*! @param natoms: atoms count. @return the isotopic pattern correponding to a fragment containing n atoms of the element. */ IsotopicPattern *GetIsotopicPattern (unsigned natoms); /*! @return the fundamental electronic configuration for the element. The returned string is formated as a pango markup, with electron numbers for each sublevel as superscript. */ std::string const& GetElectronicConfiguration () {return ElecConfig;} /*! @return the map of known names for the element indexed by language. */ std::map const& GetNames () {return names;} /*! @param rank: the rank of the ionization. @return the requested ionization energy as a &GcuDimensionalValue. */ GcuDimensionalValue const *GetIonizationEnergy (unsigned rank = 1); /*! @param rank: the rank of the electron affinity. @return the requested electron affinity as a &GcuDimensionalValue. For most elements, only the first is known. */ GcuDimensionalValue const *GetElectronAffinity (unsigned rank = 1); /*! @param property_name: the name of the property as used in the Blue Obelisk Data Repository (without the "bo:" prefix). @return the requested property if known, or NULL. */ Value const *GetProperty (char const *property_name); /*! @param property_name: the name of the property as used in the Blue Obelisk Data Repository (without the "bo:" prefix). @return the requested string property if known as a reference or an empty string. */ std::string &GetStringProperty (char const *property_name); /*! @param property_name: the name of the property as used in the Blue Obelisk Data Repository (without the "bo:" prefix). @return the requested integer property if known, or G_MININT32. */ int GetIntegerProperty (char const *property_name); /*! @return true if the element is a metal, false otherwise. */ bool IsMetallic (); private: unsigned char m_Z, m_nve, m_tve, m_maxve; char m_Symbol[4]; DimensionalValue const *m_AtomicWeight; char m_DefaultValence; unsigned char m_MaxBonds; bool m_BestSide, m_Metallic, m_MetallicCached; double m_DefaultColor[3]; std::string name; std::vector m_radii; std::vector m_en; std::vector m_isotopes; std::vector m_patterns; std::vector m_ei; std::vector m_ae; std::map names; std::map props; std::map sprops; std::map iprops; std::string ElecConfig; /*!\fn GetStability() @return true if the element has at least one stable isotope, false otherwise. */ GCU_RO_PROP (bool, Stability) }; } // namespace gcu #endif // GCU_ELEMENT_H