Browse Source

fix mol2 element symbol assignment

Alexander Rose 3 years ago
parent
commit
d61e18e6f3
2 changed files with 11 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 10 1
      src/mol-model-formats/structure/mol2.ts

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ Note that since we don't clearly distinguish between a public and private interf
 - Add PDBj as a ``pdb-provider`` option
 - Move Viewer APP to a separate file to allow use without importing light theme & index.html
 - Add symmetry support for mol2 files (only spacegroup setting 1)
+- Fix mol2 files element symbol assignment
 - Improve bond assignment from ``IndexPairBonds``
     - Add ``key`` field for mapping to source data
     - Fix assignment of bonds with unphysical length

+ 10 - 1
src/mol-model-formats/structure/mol2.ts

@@ -31,8 +31,17 @@ async function getModels(mol2: Mol2File, ctx: RuntimeContext) {
         const A = Column.ofConst('A', atoms.count, Column.Schema.str);
 
         const type_symbol = new Array<string>(atoms.count);
+        let hasAtomType = false;
         for (let i = 0; i < atoms.count; ++i) {
-            type_symbol[i] = guessElementSymbolString(atoms.atom_name.value(i));
+            if (atoms.atom_type.value(i).includes('.')) {
+                hasAtomType = true;
+                break;
+            }
+        }
+        for (let i = 0; i < atoms.count; ++i) {
+            type_symbol[i] = hasAtomType
+                ? atoms.atom_type.value(i).split('.')[0].toUpperCase()
+                : guessElementSymbolString(atoms.atom_name.value(i));
         }
 
         const atom_site = Table.ofPartialColumns(BasicSchema.atom_site, {