00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string.h>
00020 #include <ctype.h>
00021
00022
00023 static const char *pte_label[] = {
00024 "X", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne",
00025 "Na", "Mg", "Al", "Si", "P" , "S", "Cl", "Ar", "K", "Ca", "Sc",
00026 "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge",
00027 "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc",
00028 "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe",
00029 "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb",
00030 "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os",
00031 "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
00032 "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf",
00033 "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt",
00034 "Ds", "Rg"
00035 };
00036 static const int nr_pte_entries = sizeof(pte_label) / sizeof(char *);
00037
00038
00039 static const float pte_mass[] = {
00040 0.00000, 1.00794, 4.00260, 6.941, 9.012182, 10.811,
00041 12.0107, 14.0067, 15.9994, 18.9984032, 20.1797,
00042 22.989770, 24.3050, 26.981538, 28.0855, 30.973761,
00043 32.065, 35.453, 39.948, 39.0983, 40.078, 44.955910,
00044 47.867, 50.9415, 51.9961, 54.938049, 55.845, 58.9332,
00045 58.6934, 63.546, 65.409, 69.723, 72.64, 74.92160,
00046 78.96, 79.904, 83.798, 85.4678, 87.62, 88.90585,
00047 91.224, 92.90638, 95.94, 98.0, 101.07, 102.90550,
00048 106.42, 107.8682, 112.411, 114.818, 118.710, 121.760,
00049 127.60, 126.90447, 131.293, 132.90545, 137.327,
00050 138.9055, 140.116, 140.90765, 144.24, 145.0, 150.36,
00051 151.964, 157.25, 158.92534, 162.500, 164.93032,
00052 167.259, 168.93421, 173.04, 174.967, 178.49, 180.9479,
00053 183.84, 186.207, 190.23, 192.217, 195.078, 196.96655,
00054 200.59, 204.3833, 207.2, 208.98038, 209.0, 210.0, 222.0,
00055 223.0, 226.0, 227.0, 232.0381, 231.03588, 238.02891,
00056 237.0, 244.0, 243.0, 247.0, 247.0, 251.0, 252.0, 257.0,
00057 258.0, 259.0, 262.0, 261.0, 262.0, 266.0, 264.0, 269.0,
00058 268.0, 271.0, 272.0
00059 };
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static const float pte_vdw_radius[] = {
00072 1.5, 1.2, 1.4, 1.82, 2.0, 2.0,
00073 1.7, 1.55, 1.52, 1.47, 1.54,
00074 1.36, 1.18, 2.0, 2.1, 1.8,
00075 1.8, 2.27, 1.88, 1.76, 1.37, 2.0,
00076 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00077 1.63, 1.4, 1.39, 1.07, 2.0, 1.85,
00078 1.9, 1.85, 2.02, 2.0, 2.0, 2.0,
00079 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00080 1.63, 1.72, 1.58, 1.93, 2.17, 2.0,
00081 2.06, 1.98, 2.16, 2.1, 2.0,
00082 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00083 2.0, 2.0, 2.0, 2.0, 2.0,
00084 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00085 2.0, 2.0, 2.0, 2.0, 1.72, 1.66,
00086 1.55, 1.96, 2.02, 2.0, 2.0, 2.0, 2.0,
00087 2.0, 2.0, 2.0, 2.0, 2.0, 1.86,
00088 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00089 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
00090 2.0, 2.0, 2.0
00091 };
00092
00093
00094
00095 static const char *get_pte_label(const int idx)
00096 {
00097 if ((idx < 1) || (idx >= nr_pte_entries)) return pte_label[0];
00098
00099 return pte_label[idx];
00100 }
00101
00102 static float get_pte_mass(const int idx)
00103 {
00104 if ((idx < 1) || (idx >= nr_pte_entries)) return pte_mass[0];
00105
00106 return pte_mass[idx];
00107 }
00108
00109 static float get_pte_vdw_radius(const int idx)
00110 {
00111 if ((idx < 1) || (idx >= nr_pte_entries)) return pte_vdw_radius[0];
00112
00113 #if 1
00114
00115 if (idx == 1)
00116 return 1.0;
00117 #else
00118
00119 switch (idx) {
00120 case 1: return 1.0;
00121 case 6: return 1.5;
00122 case 7: return 1.4;
00123 case 8: return 1.3;
00124 case 9: return 1.2;
00125 case 15: return 1.5;
00126 case 16: return 1.9;
00127 }
00128 #endif
00129
00130 return pte_vdw_radius[idx];
00131 }
00132
00133 static int get_pte_idx(const char *label)
00134 {
00135 int i;
00136 char atom[3];
00137
00138
00139 atom[0] = (char) 0;
00140 atom[1] = (char) 0;
00141 atom[2] = (char) 0;
00142
00143
00144
00145 if (label != NULL) {
00146 atom[0] = (char) toupper((int) label[0]);
00147 atom[1] = (char) tolower((int) label[1]);
00148 }
00149
00150 if (isdigit(atom[1])) atom[1] = (char) 0;
00151
00152 for (i=0; i < nr_pte_entries; ++i) {
00153 if ( (pte_label[i][0] == atom[0])
00154 && (pte_label[i][1] == atom[1]) ) return i;
00155 }
00156
00157 return 0;
00158 }
00159
00160 static int get_pte_idx_from_string(const char *label) {
00161 int i, ind;
00162 char atom[3];
00163
00164 if (label != NULL) {
00165
00166 atom[0] = atom[1] = atom[2] = '\0';
00167
00168 for (ind=0,i=0; (ind<2) && (label[i]!='\0'); i++) {
00169 if (label[i] != ' ') {
00170 atom[ind] = toupper(label[i]);
00171 ind++;
00172 }
00173 }
00174
00175 if (ind < 1)
00176 return 0;
00177
00178 for (i=0; i < nr_pte_entries; ++i) {
00179 if ((toupper(pte_label[i][0]) == atom[0]) && (toupper(pte_label[i][1]) == atom[1]))
00180 return i;
00181 }
00182 }
00183
00184 return 0;
00185 }
00186
00187 #if 0
00188 #include <stdio.h>
00189
00190 int main() {
00191 int i;
00192
00193 printf("Periodic table check/dump\n");
00194 printf(" Table contains data for %d elements\n", nr_pte_entries);
00195 printf(" Mass table size check: %d\n", sizeof(pte_mass) / sizeof(float));
00196 printf(" VDW table size check: %d\n", sizeof(pte_vdw_radius) / sizeof(float));
00197 printf("\n");
00198 printf("Symbol Num Mass rVDW\n");
00199 for (i=0; i<nr_pte_entries; i++) {
00200 printf(" %-2s %3d %6.2f %4.2f\n",
00201 get_pte_label(i), i, get_pte_mass(i), get_pte_vdw_radius(i));
00202 }
00203 return 0;
00204 }
00205 #endif