src/io.js
function guessAtomElementFromName(fourLetterName) {
  if (fourLetterName[0] !== ' ') {
    var trimmed = fourLetterName.trim();
    if (trimmed.length === 4) {
      // look for first character in range A-Z or a-z and use that 
      // for the element. 
      var i = 0;
      var charCode = trimmed.charCodeAt(i);
      while (i < 4 && (charCode < 65 || charCode > 122 ||
             (charCode > 90 && charCode < 97))) {
        ++i;
        charCode = trimmed.charCodeAt(i);
      }
      return trimmed[i];
    }
    // when first character is not empty and length is smaller than 4,
    // assume that it's either a heavy atom (CA, etc), or a hydrogen 
    // name with a numeric prefix.  That's not always correct, though.
    var firstCharCode = trimmed.charCodeAt(0);
    if (firstCharCode >= 48 && firstCharCode <= 57) {
      // numeric prefix, so it's a hydrogen
      return trimmed[1];
    }
    return trimmed.substr(0, 2);
  }
  return fourLetterName[1];
}
function guessAtomElementFromName(fourLetterName) {
  if (fourLetterName[0] !== ' ') {
    var trimmed = fourLetterName.trim();
    if (trimmed.length === 4) {
      // look for first character in range A-Z or a-z and use that 
      // for the element. 
      var i = 0;
      var charCode = trimmed.charCodeAt(i);
      while (i < 4 && (charCode < 65 || charCode > 122 ||
             (charCode > 90 && charCode < 97))) {
        ++i;
        charCode = trimmed.charCodeAt(i);
      }
      return trimmed[i];
    }
    // when first character is not empty and length is smaller than 4,
    // assume that it's either a heavy atom (CA, etc), or a hydrogen 
    // name with a numeric prefix.  That's not always correct, though.
    var firstCharCode = trimmed.charCodeAt(0);
    if (firstCharCode >= 48 && firstCharCode <= 57) {
      // numeric prefix, so it's a hydrogen
      return trimmed[1];
    }
    return trimmed.substr(0, 2);
  }
  return fourLetterName[1];
}
function guessAtomElementFromName ( fourLetterName ) { if ( fourLetterName [ 0 ] !== ' ' ) { var trimmed = fourLetterName . trim ( ) ; if ( trimmed . length === 4 ) { // look for first character in range A-Z or a-z and use that  // for the element.  var i = 0 ; var charCode = trimmed . charCodeAt ( i ) ; while ( i < 4 && ( charCode < 65 || charCode > 122 || ( charCode > 90 && charCode < 97 ) ) ) { ++ i ; charCode = trimmed . charCodeAt ( i ) ; } return trimmed [ i ] ; } // when first character is not empty and length is smaller than 4, // assume that it's either a heavy atom (CA, etc), or a hydrogen  // name with a numeric prefix.  That's not always correct, though. var firstCharCode = trimmed . charCodeAt ( 0 ) ; if ( firstCharCode >= 48 && firstCharCode <= 57 ) { // numeric prefix, so it's a hydrogen return trimmed [ 1 ] ; } return trimmed . substr ( 0 , 2 ) ; } return fourLetterName [ 1 ] ; }
Very simple heuristic to determine the element from the atom name. This at the very least assume that people have the decency to follow the standard naming conventions for atom names when they are too lazy to write down elements
Very simple heuristic to determine the element from the atom name . This at the very least assume that people have the decency to follow the standard naming conventions for atom names when they are too lazy to write down elements