All files / src/parsers/utils atomNameToElem.ts

61.53% Statements 8/13
66.66% Branches 10/15
100% Functions 1/1
61.53% Lines 8/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24        6x 6x 4x   6x 2x 2x   2x                   6x  
import { bondTable } from "./bondTable";
 
//attempts to infer atomic element from an atom name
export function atomNameToElem(name, nothetero) {
  var elem = name.replace(/ /g, "");
  if(elem.length > 0 && elem[0] == 'H' && elem != 'Hg' && elem != 'He' && elem != 'Hf' && elem != 'Hs' && elem != 'Ho') {
      elem = 'H'; //workaround weird hydrogen names from MD, note mercury must use lowercase
  }
  if(elem.length > 1) {
      elem = elem[0].toUpperCase() + elem.substr(1).toLowerCase();   
      if(typeof(bondTable[elem]) === 'undefined') {
          //not a known element, probably should just use first letter
          elem = elem[0];
      } else IEif(nothetero) {
          if(elem == 'Ca') { //alpha carbon, not calcium
              elem = 'C';
          }
          else Iif(elem == 'Cd') {
              elem = 'C';
          }
      }
  }
  return elem;
};