Browse Source

ligand queries: fix atom count reported by SDF/MOL/MOL2 export

Sebastian Bittrich 1 year ago
parent
commit
700a3fe95c

+ 4 - 2
src/mol-io/writer/mol/encoder.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2020-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  */
@@ -29,6 +29,7 @@ export class MolEncoder extends LigandEncoder {
         // happens for the unknown ligands (UNL)
         if (!atomMap) throw Error(`The Chemical Component Dictionary doesn't hold any atom data for ${name}`);
 
+        let atomCount = 0;
         let bondCount = 0;
         let chiral = false;
 
@@ -55,6 +56,7 @@ export class MolEncoder extends LigandEncoder {
             StringBuilder.writeSafe(ctab, '  0');
             StringBuilder.writeIntegerPadLeft(ctab, this.mapCharge(charge), 3);
             StringBuilder.writeSafe(ctab, '  0  0  0  0  0  0  0  0  0  0\n');
+            atomCount++;
             if (stereo_config !== 'n') chiral = true;
 
             // no data for metal ions
@@ -76,7 +78,7 @@ export class MolEncoder extends LigandEncoder {
         });
 
         // write counts line
-        StringBuilder.writeIntegerPadLeft(this.builder, atoms.size, 3);
+        StringBuilder.writeIntegerPadLeft(this.builder, atomCount, 3);
         StringBuilder.writeIntegerPadLeft(this.builder, bondCount, 3);
         StringBuilder.writeSafe(this.builder, `  0  0  ${chiral ? 1 : 0}  0  0  0  0  0  0\n`);
 

+ 4 - 2
src/mol-io/writer/mol2/encoder.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2020-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  */
@@ -33,6 +33,7 @@ export class Mol2Encoder extends LigandEncoder {
         const bondMap = this.componentBondData.entries.get(name)!;
         // happens for the unknown ligands (UNL)
         if (!atomMap) throw Error(`The Chemical Component Dictionary doesn't hold any atom data for ${name}`);
+        let atomCount = 0;
         let bondCount = 0;
 
         const atoms = this.getAtoms(instance, source);
@@ -67,10 +68,11 @@ export class Mol2Encoder extends LigandEncoder {
 
             const sybyl = bondMap?.map ? this.mapToSybyl(label_atom_id1, type_symbol1, bondMap) : type_symbol1;
             StringBuilder.writeSafe(a, `${i1 + 1} ${label_atom_id1} ${atom1.Cartn_x.toFixed(3)} ${atom1.Cartn_y.toFixed(3)} ${atom1.Cartn_z.toFixed(3)} ${sybyl} 1 ${name} 0.000\n`);
+            atomCount++;
         });
 
         // could write something like 'SMALL\nNO_CHARGES', for now let's write **** indicating non-optional, yet missing, string values
-        StringBuilder.writeSafe(this.out, `@<TRIPOS>MOLECULE\n${name}\n${atoms.size} ${bondCount} 1\n****\n****\n\n`);
+        StringBuilder.writeSafe(this.out, `@<TRIPOS>MOLECULE\n${name}\n${atomCount} ${bondCount} 1\n****\n****\n\n`);
         StringBuilder.writeSafe(this.out, StringBuilder.getString(a));
         StringBuilder.writeSafe(this.out, StringBuilder.getString(b));
         StringBuilder.writeSafe(this.out, `@<TRIPOS>SUBSTRUCTURE\n1 ${name} 1\n`);

+ 3 - 0
src/servers/model/CHANGELOG.md

@@ -1,3 +1,6 @@
+# 0.9.10
+* /ligand queries: fix atom count reported by SDF/MOL/MOL2 export
+
 # 0.9.9
 * /ligand queries: fix behavior for alternate locations
 * /ligand queries: handle additional atoms more gracefully