@datagrok/bio 2.12.13 → 2.12.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "Aleksandr Tanas",
6
6
  "email": "atanas@datagrok.ai"
7
7
  },
8
- "version": "2.12.13",
8
+ "version": "2.12.15",
9
9
  "description": "Bioinformatics support (import/export of sequences, conversion, visualization, analysis). [See more](https://github.com/datagrok-ai/public/blob/master/packages/Bio/README.md) for details.",
10
10
  "repository": {
11
11
  "type": "git",
@@ -25,7 +25,7 @@ export class HelmToMolfileConverter {
25
25
  }
26
26
 
27
27
  private async getSmilesList(): Promise<string[]> {
28
- const molfilesV2K = (await this.convertToMolfileV2KColumn()).toList();
28
+ const molfilesV2K = (await this.convertToMolfileV3KColumn()).toList();
29
29
  const smiles = molfilesV2K.map((mol) => DG.chem.convert(mol, DG.chem.Notation.MolBlock, DG.chem.Notation.Smiles));
30
30
  return smiles;
31
31
  }
@@ -34,7 +34,7 @@ export class HelmToMolfileConverter {
34
34
  const beautifiedMolV2000 = beautifiedMols.map((mol) => {
35
35
  if (mol === null)
36
36
  return '';
37
- const molBlock = mol.get_molblock();
37
+ const molBlock = mol.get_v3Kmolblock();
38
38
  mol!.delete();
39
39
  return molBlock;
40
40
  });
@@ -52,14 +52,15 @@ export class HelmToMolfileConverter {
52
52
  }
53
53
 
54
54
  async convertToRdKitBeautifiedMolfileColumn(chiralityEngine?: boolean): Promise<DG.Column<string>> {
55
- const smiles = await this.getSmilesList();
55
+ const molfilesV3K = (await this.convertToMolfileV3KColumn()).toList();
56
56
  const rdKitModule: RDModule = await grok.functions.call('Chem:getRdKitModule');
57
- const beautifiedMols = smiles.map((item) =>{
57
+ const beautifiedMols = molfilesV3K.map((item) =>{
58
58
  if (item === '')
59
59
  return null;
60
60
  const mol = rdKitModule.get_mol(item);
61
61
  if (!mol)
62
62
  return null;
63
+ mol.set_new_coords();
63
64
  mol.normalize_depiction(1);
64
65
  mol.straighten_depiction(true);
65
66
  return mol;
@@ -77,7 +78,7 @@ export class HelmToMolfileConverter {
77
78
  }));
78
79
  }
79
80
 
80
- private async convertToMolfileV2KColumn(): Promise<DG.Column<string>> {
81
+ private async convertToMolfileV3KColumn(): Promise<DG.Column<string>> {
81
82
  const polymerGraphColumn: DG.Column<string> = await this.getPolymerGraphColumn();
82
83
  const rdKitModule = await grok.functions.call('Chem:getRdKitModule');
83
84
  const molfileList = polymerGraphColumn.toList().map(
@@ -1,7 +1,7 @@
1
1
  import {MolfileHandlerBase} from '@datagrok-libraries/chem-meta/src/parsing-utils/molfile-handler-base';
2
2
  import {MolfileAtoms} from './mol-atoms';
3
3
 
4
- const PRECISION = 6;
4
+ const PRECISION = 4;
5
5
 
6
6
  export class MolfileAtomsV3K extends MolfileAtoms {
7
7
  constructor(private molfileHandler: MolfileHandlerBase) {
@@ -21,13 +21,13 @@ export class MolfileAtomsV3K extends MolfileAtoms {
21
21
 
22
22
  get atomLines(): string[] {
23
23
  // todo: optimize, optionally port to molfile-handler
24
- const coordinateRegex = /^(M V30 .*)(-?\d+\.\d+)( )(-?\d+\.\d+)( -?\d+\.\d+.*)$/;
24
+ const coordinateRegex = /^(M V30 [^-]*)(-?\d+\.\d+)( )(-?\d+\.\d+)( -?\d+\.\d+.*)$/;
25
25
  const rGroupsRegex = /\sRGROUPS=\(\d+(\s+\d+)*\)/;
26
26
 
27
27
  return this.rawAtomLines.map((line: string, idx: number) => {
28
28
  const coordinates = this.coordinates[idx];
29
- const x = coordinates.x.toFixed(PRECISION);
30
- const y = coordinates.y.toFixed(PRECISION);
29
+ const x = coordinates.x.toFixed(PRECISION) + '00';
30
+ const y = coordinates.y.toFixed(PRECISION) + '00';
31
31
 
32
32
  return line.replace(coordinateRegex, (match, p1, p2, p3, p4, p5) => {
33
33
  return p1 + x + p3 + y + p5;
@@ -1,6 +1,6 @@
1
1
  import {Monomer} from '@datagrok-libraries/bio/src/types';
2
2
  import {HELM_RGROUP_FIELDS} from '@datagrok-libraries/bio/src/utils/const';
3
- import {RDModule} from '@datagrok-libraries/chem-meta/src/rdkit-api';
3
+ import {RDModule, RDMol} from '@datagrok-libraries/chem-meta/src/rdkit-api';
4
4
  import {MonomerLibManager} from '../../monomer-lib/lib-manager';
5
5
  import {Helm} from './helm';
6
6
  import {MolfileWrapper} from './mol-wrapper';
@@ -22,7 +22,7 @@ export class MonomerWrapper {
22
22
 
23
23
  let molfile = libraryMonomerObject.molfile;
24
24
  if (MolfileHandler.isMolfileV2K(molfile))
25
- molfile = this.convertMolfileToV3KFormat(molfile, rdKitModule);
25
+ molfile = this.convertMolfileToV3KFormat(molfile, monomerSymbol, rdKitModule);
26
26
 
27
27
  this.molfileWrapper = MolfileWrapperFactory.getInstance(molfile, monomerSymbol);
28
28
  this.capGroupElements = this.getCapGroupElements(libraryMonomerObject);
@@ -34,8 +34,17 @@ export class MonomerWrapper {
34
34
  this.shiftCoordinates(shift);
35
35
  }
36
36
 
37
- private convertMolfileToV3KFormat(molfileV2K: string, rdKitModule: RDModule): string {
38
- return rdKitModule.get_mol(molfileV2K, JSON.stringify({mergeQueryHs: true})).get_v3Kmolblock();
37
+ private convertMolfileToV3KFormat(molfileV2K: string, monomerSymbol: string, rdKitModule: RDModule): string {
38
+ let mol: RDMol | null = null;
39
+ try {
40
+ mol = rdKitModule.get_mol(molfileV2K, JSON.stringify({mergeQueryHs: true}))
41
+ if (mol)
42
+ return mol.get_v3Kmolblock();
43
+ else
44
+ throw new Error(`Cannot convert ${monomerSymbol} to molV3000`);
45
+ } finally {
46
+ mol?.delete();
47
+ }
39
48
  }
40
49
 
41
50
  private getLibraryMonomerObject(): Monomer {
@@ -72,7 +72,7 @@ export class Polymer {
72
72
  }
73
73
 
74
74
  private getV3KHeader(atomCount: number, bondCount: number): string {
75
- const countsLine = `${V3K_CONST.COUNTS_LINE_START}${atomCount} ${bondCount}${V3K_CONST.COUNTS_LINE_DUMMY_END}`;
75
+ const countsLine = `${V3K_CONST.COUNTS_LINE_START}${atomCount} ${bondCount} 0 0 1`;
76
76
  return `${V3K_CONST.DUMMY_HEADER}\n${V3K_CONST.BEGIN_CTAB}\n${countsLine}`;
77
77
  }
78
78