LCOV - code coverage report
Current view: top level - molfile - periodic_table.h (source / functions) Hit Total Coverage
Test: plumed test coverage (other modules) Lines: 0 20 0.0 %
Date: 2024-10-11 08:09:49 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             : University of Illinois Open Source License
       3             : Copyright 2003 Theoretical and Computational Biophysics Group, 
       4             : All rights reserved.
       5             : 
       6             : Developed by:           Theoretical and Computational Biophysics Group
       7             :                         University of Illinois at Urbana-Champaign
       8             :                         http://www.ks.uiuc.edu/
       9             : 
      10             : Permission is hereby granted, free of charge, to any person obtaining a copy of
      11             : this software and associated documentation files (the Software), to deal with 
      12             : the Software without restriction, including without limitation the rights to 
      13             : use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
      14             : of the Software, and to permit persons to whom the Software is furnished to 
      15             : do so, subject to the following conditions:
      16             : 
      17             : Redistributions of source code must retain the above copyright notice, 
      18             : this list of conditions and the following disclaimers.
      19             : 
      20             : Redistributions in binary form must reproduce the above copyright notice, 
      21             : this list of conditions and the following disclaimers in the documentation 
      22             : and/or other materials provided with the distribution.
      23             : 
      24             : Neither the names of Theoretical and Computational Biophysics Group, 
      25             : University of Illinois at Urbana-Champaign, nor the names of its contributors 
      26             : may be used to endorse or promote products derived from this Software without 
      27             : specific prior written permission.
      28             : 
      29             : THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
      30             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
      31             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL 
      32             : THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
      33             : OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
      34             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
      35             : OTHER DEALINGS WITH THE SOFTWARE.
      36             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      37             : #ifndef __PLUMED_molfile_periodic_table_h
      38             : #define __PLUMED_molfile_periodic_table_h
      39             : /***************************************************************************
      40             :  * RCS INFORMATION:
      41             :  *
      42             :  *      $RCSfile: periodic_table.h,v $
      43             :  *      $Author: johns $       $Locker:  $             $State: Exp $
      44             :  *      $Revision: 1.12 $       $Date: 2009/01/21 17:45:41 $
      45             :  *
      46             :  ***************************************************************************/
      47             : 
      48             : /*
      49             :  * periodic table of elements and helper functions to convert
      50             :  * ordinal numbers to labels and back.
      51             :  * all tables and functions are declared static, so that it
      52             :  * can be safely included by all plugins that may need it.
      53             :  *
      54             :  * 2002-2009 akohlmey@cmm.chem.upenn.edu, vmd@ks.uiuc.edu
      55             :  */
      56             : 
      57             : #include <string.h>
      58             : #include <ctype.h>
      59             : 
      60             : namespace PLMD{
      61             : namespace molfile{
      62             : /* periodic table of elements for translation of ordinal to atom type */
      63             : static const char *pte_label[] = { 
      64             :     "X",  "H",  "He", "Li", "Be", "B",  "C",  "N",  "O",  "F",  "Ne",
      65             :     "Na", "Mg", "Al", "Si", "P" , "S",  "Cl", "Ar", "K",  "Ca", "Sc",
      66             :     "Ti", "V",  "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", 
      67             :     "As", "Se", "Br", "Kr", "Rb", "Sr", "Y",  "Zr", "Nb", "Mo", "Tc",
      68             :     "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I",  "Xe",
      69             :     "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb",
      70             :     "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W",  "Re", "Os",
      71             :     "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
      72             :     "Ra", "Ac", "Th", "Pa", "U",  "Np", "Pu", "Am", "Cm", "Bk", "Cf",
      73             :     "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt",
      74             :     "Ds", "Rg"
      75             : };
      76             : static const int nr_pte_entries = sizeof(pte_label) / sizeof(char *);
      77             : 
      78             : /* corresponding table of masses. */
      79             : static const float pte_mass[] = { 
      80             :     /* X  */ 0.00000, 1.00794, 4.00260, 6.941, 9.012182, 10.811,  
      81             :     /* C  */ 12.0107, 14.0067, 15.9994, 18.9984032, 20.1797, 
      82             :     /* Na */ 22.989770, 24.3050, 26.981538, 28.0855, 30.973761,
      83             :     /* S  */ 32.065, 35.453, 39.948, 39.0983, 40.078, 44.955910,
      84             :     /* Ti */ 47.867, 50.9415, 51.9961, 54.938049, 55.845, 58.9332,
      85             :     /* Ni */ 58.6934, 63.546, 65.409, 69.723, 72.64, 74.92160, 
      86             :     /* Se */ 78.96, 79.904, 83.798, 85.4678, 87.62, 88.90585, 
      87             :     /* Zr */ 91.224, 92.90638, 95.94, 98.0, 101.07, 102.90550,
      88             :     /* Pd */ 106.42, 107.8682, 112.411, 114.818, 118.710, 121.760, 
      89             :     /* Te */ 127.60, 126.90447, 131.293, 132.90545, 137.327, 
      90             :     /* La */ 138.9055, 140.116, 140.90765, 144.24, 145.0, 150.36,
      91             :     /* Eu */ 151.964, 157.25, 158.92534, 162.500, 164.93032, 
      92             :     /* Er */ 167.259, 168.93421, 173.04, 174.967, 178.49, 180.9479,
      93             :     /* W  */ 183.84, 186.207, 190.23, 192.217, 195.078, 196.96655, 
      94             :     /* Hg */ 200.59, 204.3833, 207.2, 208.98038, 209.0, 210.0, 222.0, 
      95             :     /* Fr */ 223.0, 226.0, 227.0, 232.0381, 231.03588, 238.02891,
      96             :     /* Np */ 237.0, 244.0, 243.0, 247.0, 247.0, 251.0, 252.0, 257.0,
      97             :     /* Md */ 258.0, 259.0, 262.0, 261.0, 262.0, 266.0, 264.0, 269.0,
      98             :     /* Mt */ 268.0, 271.0, 272.0
      99             : };
     100             : 
     101             : /*
     102             :  * corresponding table of VDW radii.
     103             :  * van der Waals radii are taken from A. Bondi, 
     104             :  * J. Phys. Chem., 68, 441 - 452, 1964, 
     105             :  * except the value for H, which is taken from R.S. Rowland & R. Taylor, 
     106             :  * J.Phys.Chem., 100, 7384 - 7391, 1996. Radii that are not available in 
     107             :  * either of these publications have RvdW = 2.00 Å.
     108             :  * The radii for Ions (Na, K, Cl, Ca, Mg, and Cs are based on the CHARMM27 
     109             :  * Rmin/2 parameters for (SOD, POT, CLA, CAL, MG, CES) by default.
     110             :  */
     111             : static const float pte_vdw_radius[] = { 
     112             :     /* X  */ 1.5, 1.2, 1.4, 1.82, 2.0, 2.0,  
     113             :     /* C  */ 1.7, 1.55, 1.52, 1.47, 1.54, 
     114             :     /* Na */ 1.36, 1.18, 2.0, 2.1, 1.8,
     115             :     /* S  */ 1.8, 2.27, 1.88, 1.76, 1.37, 2.0,
     116             :     /* Ti */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     117             :     /* Ni */ 1.63, 1.4, 1.39, 1.07, 2.0, 1.85,
     118             :     /* Se */ 1.9, 1.85, 2.02, 2.0, 2.0, 2.0, 
     119             :     /* Zr */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     120             :     /* Pd */ 1.63, 1.72, 1.58, 1.93, 2.17, 2.0, 
     121             :     /* Te */ 2.06, 1.98, 2.16, 2.1, 2.0,
     122             :     /* La */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     123             :     /* Eu */ 2.0, 2.0, 2.0, 2.0, 2.0,
     124             :     /* Er */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     125             :     /* W  */ 2.0, 2.0, 2.0, 2.0, 1.72, 1.66,
     126             :     /* Hg */ 1.55, 1.96, 2.02, 2.0, 2.0, 2.0, 2.0,
     127             :     /* Fr */ 2.0, 2.0, 2.0, 2.0, 2.0, 1.86,
     128             :     /* Np */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     129             :     /* Md */ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
     130             :     /* Mt */ 2.0, 2.0, 2.0
     131             : };
     132             : 
     133             : /* lookup functions */
     134             : 
     135           0 : static const char *get_pte_label(const int idx)
     136             : {
     137           0 :     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_label[0];
     138             : 
     139           0 :     return pte_label[idx];
     140             : }
     141             : 
     142           0 : static float get_pte_mass(const int idx)
     143             : {
     144           0 :     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_mass[0];
     145             : 
     146           0 :     return pte_mass[idx];
     147             : }
     148             : 
     149           0 : static float get_pte_vdw_radius(const int idx)
     150             : {
     151           0 :     if ((idx < 1) || (idx >= nr_pte_entries)) return pte_vdw_radius[0];
     152             : 
     153             : #if 1
     154             :     /* Replace with Hydrogen radius with an "all-atom" radius */
     155           0 :     if (idx == 1)
     156             :       return 1.0;    /* H  */
     157             : #else
     158             :     /* Replace with old VMD atom radii values */
     159             :     switch (idx) {
     160             :       case  1: return 1.0;    /* H  */
     161             :       case  6: return 1.5;    /* C  */
     162             :       case  7: return 1.4;    /* N  */
     163             :       case  8: return 1.3;    /* O  */
     164             :       case  9: return 1.2;    /* F  */
     165             :       case 15: return 1.5;    /* P  */
     166             :       case 16: return 1.9;    /* S  */ 
     167             :     }
     168             : #endif
     169             : 
     170           0 :     return pte_vdw_radius[idx];
     171             : }
     172             : 
     173             : static int get_pte_idx(const char *label)
     174             : {
     175             :     int i;
     176             :     char atom[3];
     177             :     
     178             :     /* zap string */
     179             :     atom[0] = (char) 0;
     180             :     atom[1] = (char) 0;
     181             :     atom[2] = (char) 0;
     182             :     /* if we don't have a null-pointer, there must be at least two 
     183             :      * chars, which is all we need. we convert to the capitalization 
     184             :      * convention of the table above during assignment. */
     185             :     if (label != NULL) {
     186             :         atom[0] = (char) toupper((int) label[0]);
     187             :         atom[1] = (char) tolower((int) label[1]);
     188             :     }
     189             :     /* discard numbers in atom label */
     190             :     if (isdigit(atom[1])) atom[1] = (char) 0;
     191             :     
     192             :     for (i=0; i < nr_pte_entries; ++i) {
     193             :         if ( (pte_label[i][0] == atom[0])
     194             :              && (pte_label[i][1] == atom[1]) ) return i;
     195             :     }
     196             :     
     197             :     return 0;
     198             : }
     199             : 
     200           0 : static int get_pte_idx_from_string(const char *label) {
     201             :   int i, ind;
     202             :   char atom[3];
     203             : 
     204           0 :   if (label != NULL) {
     205             :     /* zap string */
     206           0 :     atom[0] = atom[1] = atom[2] = '\0';
     207             : 
     208           0 :     for (ind=0,i=0; (ind<2) && (label[i]!='\0'); i++) {
     209           0 :       if (label[i] != ' ') {
     210           0 :         atom[ind] = toupper(label[i]);
     211           0 :         ind++;
     212             :       }
     213             :     }
     214             : 
     215           0 :     if (ind < 1)
     216             :       return 0; /* no non-whitespace characters */
     217             :  
     218           0 :     for (i=0; i < nr_pte_entries; ++i) {
     219           0 :       if ((toupper(pte_label[i][0]) == atom[0]) && (toupper(pte_label[i][1]) == atom[1])) 
     220             :         return i;
     221             :     }
     222             :   }  
     223             : 
     224             :   return 0;
     225             : }
     226             : 
     227             : #if 0
     228             : #include <stdio.h>
     229             : 
     230             : int main() {
     231             :   int i;
     232             : 
     233             :   printf("Periodic table check/dump\n");
     234             :   printf("  Table contains data for %d elements\n", nr_pte_entries);
     235             :   printf("   Mass table size check: %d\n", sizeof(pte_mass) / sizeof(float));
     236             :   printf("    VDW table size check: %d\n", sizeof(pte_vdw_radius) / sizeof(float));
     237             :   printf("\n");
     238             :   printf("Symbol Num    Mass   rVDW\n");
     239             :   for (i=0; i<nr_pte_entries; i++) {
     240             :     printf("   %-2s  %3d  %6.2f  %4.2f\n",
     241             :       get_pte_label(i), i, get_pte_mass(i), get_pte_vdw_radius(i));
     242             :   } 
     243             :   return 0;
     244             : }
     245             : #endif
     246             : }
     247             : }
     248             : #endif

Generated by: LCOV version 1.15