icn3d 3.51.0 → 3.51.2

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/icn3d.js CHANGED
@@ -84127,18 +84127,30 @@ class ApplyClbonds {
84127
84127
  if(clbondArray === undefined) {
84128
84128
  break;
84129
84129
  }
84130
- for(let i = 0, il = clbondArray.length; i < il; i = i + 2) {
84131
- let resid1 = clbondArray[i];
84132
- let resid2 = clbondArray[i+1];
84133
84130
 
84134
- let atom1 = ic.firstAtomObjCls.getFirstAtomObj(ic.residues[resid1]);
84135
- let atom2 = ic.firstAtomObjCls.getFirstAtomObj(ic.residues[resid2]);
84131
+ let clusterArray = this.clusterLinkedNodes(clbondArray);
84132
+
84133
+ for(let i = 0, il = clusterArray.length; i < il; ++i) {
84134
+ let rootResid = 0;
84135
+ for(let j = 0, jl = clusterArray[i].length; j < jl; ++j) {
84136
+ let resid = clusterArray[i][j];
84137
+ let atom = ic.firstAtomObjCls.getFirstAtomObj(ic.residues[resid]);
84136
84138
 
84137
- if((ic.proteins.hasOwnProperty(atom1.serial) || ic.nucleotides.hasOwnProperty(atom1.serial)) && ic.chemicals.hasOwnProperty(atom2.serial)) {
84138
- ic.residues[resid1] = me.hashUtilsCls.unionHash(ic.residues[resid1], ic.residues[resid2]);
84139
+ if(ic.proteins.hasOwnProperty(atom.serial) || ic.nucleotides.hasOwnProperty(atom.serial)) {
84140
+ rootResid = resid;
84141
+ break;
84142
+ }
84139
84143
  }
84140
- else if((ic.proteins.hasOwnProperty(atom2.serial) || ic.nucleotides.hasOwnProperty(atom2.serial)) && ic.chemicals.hasOwnProperty(atom1.serial)) {
84141
- ic.residues[resid2] = me.hashUtilsCls.unionHash(ic.residues[resid2], ic.residues[resid1]);
84144
+
84145
+ if(rootResid) {
84146
+ for(let j = 0, jl = clusterArray[i].length; j < jl; ++j) {
84147
+ let resid = clusterArray[i][j];
84148
+ let atom = ic.firstAtomObjCls.getFirstAtomObj(ic.residues[resid]);
84149
+
84150
+ if(ic.chemicals.hasOwnProperty(atom.serial)) {
84151
+ ic.residues[rootResid] = me.hashUtilsCls.unionHash(ic.residues[rootResid], ic.residues[resid]);
84152
+ }
84153
+ }
84142
84154
  }
84143
84155
  }
84144
84156
  }
@@ -84146,6 +84158,45 @@ class ApplyClbonds {
84146
84158
  return ic.residuesHashClbonds;
84147
84159
  }
84148
84160
 
84161
+ clusterLinkedNodes(clbondArray) { let ic = this.icn3d; ic.icn3dui;
84162
+ const parent = new Map();
84163
+
84164
+ // Find the root of a node, with path compression
84165
+ function find(node) {
84166
+ if (!parent.has(node)) parent.set(node, node);
84167
+ if (parent.get(node) !== node) {
84168
+ parent.set(node, find(parent.get(node))); // path compression
84169
+ }
84170
+ return parent.get(node);
84171
+ }
84172
+
84173
+ // Union two nodes into the same cluster
84174
+ function union(a, b) {
84175
+ const rootA = find(a);
84176
+ const rootB = find(b);
84177
+ if (rootA !== rootB) parent.set(rootA, rootB);
84178
+ }
84179
+
84180
+ // Process all pairs
84181
+ // for (const [a, b] of pairs) {
84182
+ // union(a, b);
84183
+ // }
84184
+
84185
+ for(let i = 0, il = clbondArray.length; i < il; i = i + 2) {
84186
+ union(clbondArray[i], clbondArray[i+1]);
84187
+ }
84188
+
84189
+ // Group nodes by their root
84190
+ const clusters = new Map();
84191
+ for (const node of parent.keys()) {
84192
+ const root = find(node);
84193
+ if (!clusters.has(root)) clusters.set(root, []);
84194
+ clusters.get(root).push(node);
84195
+ }
84196
+
84197
+ return Array.from(clusters.values());
84198
+ }
84199
+
84149
84200
  applyClbondsOptions_base(type) { let ic = this.icn3d, me = ic.icn3dui;
84150
84201
  // only apply to displayed atoms
84151
84202
  let atomHash = me.hashUtilsCls.cloneHash(ic.chemicals);
@@ -84248,6 +84299,9 @@ class ApplyMissingRes {
84248
84299
  let bStart = false;
84249
84300
  let startResid, currResid, prevResid;
84250
84301
  let bCurrCoord, bPrevCoord = false;
84302
+
84303
+ if(!ic.chainsSeq[chainid]) continue;
84304
+
84251
84305
  for(let i = 0, il = ic.chainsSeq[chainid].length; i < il; ++i) {
84252
84306
  currResid = chainid + '_' + ic.chainsSeq[chainid][i].resi;
84253
84307
 
@@ -100931,6 +100985,8 @@ class GetGraph {
100931
100985
  "#" + ic.hColor.getHexString().toUpperCase();
100932
100986
  let pos = node.id.indexOf('.');
100933
100987
  let nodeName =(pos == -1) ? node.id : node.id.substr(0, pos);
100988
+ if(nodeName.length > 4) nodeName = nodeName.substr(0, 1) + '..' + nodeName.substr(nodeName.length - 2);
100989
+
100934
100990
  let adjustx = 0, adjusty =(setName == 'a') ? -7 : 10;
100935
100991
  if(i % 2 == 1) adjusty =(setName == 'a') ? adjusty - 7 : adjusty + 7;
100936
100992
 
@@ -107248,11 +107304,11 @@ class BcifParser {
107248
107304
 
107249
107305
  let chain1Array = struct_conn.getColumn("ptnr1_auth_asym_id");
107250
107306
  let name1Array = struct_conn.getColumn("ptnr1_label_atom_id");
107251
- let resi1Array = struct_conn.getColumn("ptnr1_label_seq_id");
107307
+ let resi1Array = struct_conn.getColumn("ptnr1_auth_seq_id");
107252
107308
 
107253
107309
  let chain2Array = struct_conn.getColumn("ptnr2_auth_asym_id");
107254
107310
  let name2Array = struct_conn.getColumn("ptnr2_label_atom_id");
107255
- let resi2Array = struct_conn.getColumn("ptnr2_label_seq_id");
107311
+ let resi2Array = struct_conn.getColumn("ptnr2_auth_seq_id");
107256
107312
 
107257
107313
  let connSize = struct_conn.rowCount;
107258
107314
  for (let i = 0; i < connSize; ++i) {
@@ -107444,7 +107500,7 @@ class BcifParser {
107444
107500
  else {
107445
107501
  // bond between this atom and all other atom in the same residue
107446
107502
  for(let j in mResi2Atoms[currResi]) { // j is atom.id
107447
- if(this.hasCovalentBond(atom, mResi2Atoms[currResi][j], para)) {
107503
+ if(this.hasCovalentBond2(atom, mResi2Atoms[currResi][j], para)) {
107448
107504
  if(!mId2Set.hasOwnProperty(atom.id)) mId2Set[atom.id] = {};
107449
107505
  if(!mId2Set.hasOwnProperty(mResi2Atoms[currResi][j].id)) mId2Set[mResi2Atoms[currResi][j].id] = {};
107450
107506
  mId2Set[atom.id][mResi2Atoms[currResi][j].id] = 1;
@@ -107457,7 +107513,7 @@ class BcifParser {
107457
107513
 
107458
107514
  // bond between N and previous C
107459
107515
  if(name == "N" && prevC.id != "") {
107460
- if(this.hasCovalentBond(atom, prevC, para)) {
107516
+ if(this.hasCovalentBond2(atom, prevC, para)) {
107461
107517
  if(!mId2Set.hasOwnProperty(atom.id)) mId2Set[atom.id] = {};
107462
107518
  if(!mId2Set.hasOwnProperty(prevC.id)) mId2Set[prevC.id] = {};
107463
107519
  mId2Set[atom.id][prevC.id] = 1;
@@ -107798,7 +107854,7 @@ class BcifParser {
107798
107854
  return text;
107799
107855
  }
107800
107856
 
107801
- hasCovalentBond(atom1, atom2, para) { let ic = this.icn3d; ic.icn3dui;
107857
+ hasCovalentBond2(atom1, atom2, para) { let ic = this.icn3d; ic.icn3dui;
107802
107858
  let r = this.mElem2Radius[atom1.elem] + this.mElem2Radius[atom2.elem];
107803
107859
 
107804
107860
  let dx = (atom1.x - atom2.x);
@@ -116072,6 +116128,10 @@ class LoadPDB {
116072
116128
  setResidMapping() { let ic = this.icn3d; ic.icn3dui;
116073
116129
  // set ic.ncbi2resid and ic.resid2ncbi
116074
116130
  for(let chainid in ic.chainsSeq) {
116131
+ if(!ic.chainsSeq[chainid]) {
116132
+ continue;
116133
+ }
116134
+
116075
116135
  for(let j = 0, jl = ic.chainsSeq[chainid].length; j < jl; ++j) {
116076
116136
  // NCBI residue number starts from 1 and increases continuously
116077
116137
  let residNCBI = chainid + '_' + (j+1).toString();
@@ -116421,6 +116481,7 @@ class LoadCIF {
116421
116481
  chain1Array = resi1Array = resi2Array = [];
116422
116482
  }
116423
116483
 
116484
+ // let vBonds = [];
116424
116485
  if(block.getCategory("_struct_conn")) {
116425
116486
  ic.bSsbondProvided = true;
116426
116487
 
@@ -116431,11 +116492,13 @@ class LoadCIF {
116431
116492
 
116432
116493
  let chain1Array = struct_conn.getColumn("ptnr1_auth_asym_id");
116433
116494
  let name1Array = struct_conn.getColumn("ptnr1_label_atom_id");
116434
- let resi1Array = struct_conn.getColumn("ptnr1_label_seq_id");
116495
+ let resi1Array = struct_conn.getColumn("ptnr1_auth_seq_id");
116496
+ // let resn1Array = struct_conn.getColumn("ptnr1_auth_comp_id");
116435
116497
 
116436
116498
  let chain2Array = struct_conn.getColumn("ptnr2_auth_asym_id");
116437
116499
  let name2Array = struct_conn.getColumn("ptnr2_label_atom_id");
116438
- let resi2Array = struct_conn.getColumn("ptnr2_label_seq_id");
116500
+ let resi2Array = struct_conn.getColumn("ptnr2_auth_seq_id");
116501
+ // let resn2Array = struct_conn.getColumn("ptnr2_auth_comp_id");
116439
116502
 
116440
116503
  let connSize = struct_conn.rowCount;
116441
116504
  for (let i = 0; i < connSize; ++i) {
@@ -116444,21 +116507,24 @@ class LoadCIF {
116444
116507
  let chain1 = chain1Array.getString(i);
116445
116508
  name1Array.getString(i);
116446
116509
  let resi1 = resi1Array.getString(i);
116510
+ // let resn1 = resn1Array.getString(i);
116447
116511
  let id1 = structure + '_' + chain1 + "_" + resi1;
116512
+
116513
+ // let chain1Tmp = (me.parasCls.residueAbbrev.hasOwnProperty(resn1)) ? chain1 : resn1;
116514
+ // let bondId1 = chain1Tmp + "_" + resi1 + "_" + name1;
116448
116515
 
116449
116516
  let chain2 = chain2Array.getString(i);
116450
116517
  name2Array.getString(i);
116451
116518
  let resi2 = resi2Array.getString(i);
116519
+ // let resn2 = resn2Array.getString(i);
116452
116520
  let id2 = structure + '_' + chain2 + "_" + resi2;
116453
-
116454
- // Verify that the linkage is covalent, as indicated by the conn_type_id attribute2
116455
-
116456
- // if (conn_type_id == "covale") {
116457
- // vBonds.push(id1);
116458
- // vBonds.push(id2);
116459
- // }
116460
-
116461
- if(conn_type_id == "disulf") {
116521
+
116522
+ // let chain2Tmp = (me.parasCls.residueAbbrev.hasOwnProperty(resn2)) ? chain2 : resn2;
116523
+ // let bondId2 = chain2Tmp + "_" + resi2 + "_" + name2;
116524
+
116525
+ // Verify that the linkage is covalent, as indicated by the conn_type_id attribute2
116526
+ if (conn_type_id == "covale") ;
116527
+ else if(conn_type_id == "disulf") {
116462
116528
  if(ic.ssbondpnts[structure] === undefined) ic.ssbondpnts[structure] = [];
116463
116529
 
116464
116530
  ic.ssbondpnts[structure].push(id1);
@@ -116591,6 +116657,7 @@ class LoadCIF {
116591
116657
  let nameArray = atom_site.getColumn("label_atom_id");
116592
116658
  let entiyidArray = atom_site.getColumn("label_entity_id");
116593
116659
 
116660
+ // check 3QUM
116594
116661
  let chainArray = atom_site.getColumn("auth_asym_id");
116595
116662
 
116596
116663
  let resiArray = atom_site.getColumn("label_seq_id");
@@ -116612,7 +116679,6 @@ class LoadCIF {
116612
116679
  let sChain = {};
116613
116680
  let prevModelNum = '';
116614
116681
  if(!ic.molid2chain) ic.molid2chain = {};
116615
-
116616
116682
  for (let i = 0; i < atomSize; ++i) {
116617
116683
  let modelNum = modelNumArray.getString(i);
116618
116684
  if(i > 0 && modelNum != prevModelNum) {
@@ -116640,7 +116706,6 @@ class LoadCIF {
116640
116706
 
116641
116707
  let autochain = autochainArray.getString(i);
116642
116708
 
116643
-
116644
116709
  resi = oriResi;
116645
116710
 
116646
116711
  let molecueType;
@@ -116659,7 +116724,7 @@ class LoadCIF {
116659
116724
  }
116660
116725
  else {
116661
116726
  molecueType = "ligand"; // ligands or ions
116662
- chain = resn;
116727
+ if(chain == "?" || chain == ".") chain = resn; // check 3QUM
116663
116728
  }
116664
116729
  }
116665
116730
  if(chain === '') chain = 'A';
@@ -116749,6 +116814,8 @@ class LoadCIF {
116749
116814
  let z = zArray.getFloat(i);
116750
116815
  let coord = new Vector3$1(x, y, z);
116751
116816
 
116817
+ let id = serial.toString();
116818
+
116752
116819
  let atomDetails = {
116753
116820
  het: (atom_hetatm == "HETATM"), // optional, used to determine chemicals, water, ions, etc
116754
116821
  serial: serial, // required, unique atom id
@@ -116905,6 +116972,30 @@ class LoadCIF {
116905
116972
  ic.residues[residueNum] = residuesTmp;
116906
116973
  if(ic.chains[chainNum] === undefined) ic.chains[chainNum] = {};
116907
116974
  ic.chains[chainNum] = me.hashUtilsCls.unionHash2Atoms(ic.chains[chainNum], chainsTmp, ic.atoms);
116975
+ /*
116976
+ /// add the defined bonds
116977
+ for(let i = 0; i < vBonds.length; i = i + 2) {
116978
+ let id1 = mName2Serial[vBonds[i]];
116979
+ let id2 = mName2Serial[vBonds[i+1]];
116980
+
116981
+ if(!mId2Set.hasOwnProperty(id1)) mId2Set[id1] = {};
116982
+ if(!mId2Set.hasOwnProperty(id2)) mId2Set[id2] = {};
116983
+ mId2Set[id1][id2] = 1;
116984
+ mId2Set[id2][id1] = 1;
116985
+ }
116986
+
116987
+ for(let id in mId2Set) {
116988
+ let sConnId = mId2Set[id];
116989
+ let vConnId = Object.keys(sConnId);
116990
+ let serial = parseInt(id);
116991
+
116992
+ for(let j = 0, jl = vConnId.length; j < jl; ++j) {
116993
+ if(vConnId[j] === 'undefined' || !ic.atoms[serial]) continue;
116994
+ if(!ic.atoms[serial].bonds) ic.atoms[serial].bonds = [];
116995
+ ic.atoms[serial].bonds.push(parseInt(vConnId[j]));
116996
+ }
116997
+ }
116998
+ */
116908
116999
 
116909
117000
  // clear memory
116910
117001
  atom_hetatmArray = resnArray = elemArray = nameArray = chainArray = resiArray = resiOriArray
@@ -117076,6 +117167,41 @@ class LoadCIF {
117076
117167
  }
117077
117168
  }
117078
117169
 
117170
+ // check the bonds between chemicals and all other atoms
117171
+ let processedChemicals = {};
117172
+ for(let i in ic.chemicals) {
117173
+ console.log(" i = ", i, " processedChemicals = ", processedChemicals);
117174
+ if(processedChemicals.hasOwnProperty(i)) continue;
117175
+
117176
+ let atom = ic.atoms[i];
117177
+ let resid = atom.structure + '_' + atom.chain + '_' + atom.resi;
117178
+
117179
+ let radius = 4;
117180
+ let residueAtoms = ic.residues[resid];
117181
+ let otherAtoms = me.hashUtilsCls.exclHash(ic.atoms, residueAtoms);
117182
+ let neighborAtoms = ic.contactCls.getAtomsWithinAtom(otherAtoms, residueAtoms, radius);
117183
+
117184
+ for(let j in residueAtoms) {
117185
+ let startAtom = ic.atoms[j];
117186
+ for(let k in neighborAtoms) {
117187
+ let neighborAtom = ic.atoms[k];
117188
+ let neighborResid = neighborAtom.structure + '_' + neighborAtom.chain + '_' + neighborAtom.resi;
117189
+ if(resid === neighborResid) continue;
117190
+
117191
+ if(me.utilsCls.hasCovalentBond(startAtom, neighborAtom)) {
117192
+ // Handle covalent bond
117193
+ if(!startAtom.bonds) startAtom.bonds = [];
117194
+ if(!neighborAtom.bonds) neighborAtom.bonds = [];
117195
+
117196
+ startAtom.bonds.push(neighborAtom.serial);
117197
+ neighborAtom.bonds.push(startAtom.serial);
117198
+ }
117199
+ }
117200
+ }
117201
+
117202
+ processedChemicals = me.hashUtilsCls.unionHash(processedChemicals, ic.residues[resid]);
117203
+ }
117204
+
117079
117205
  ic.pmin = pmin;
117080
117206
  ic.pmax = pmax;
117081
117207
 
@@ -135737,7 +135863,7 @@ class iCn3DUI {
135737
135863
  //even when multiple iCn3D viewers are shown together.
135738
135864
  this.pre = this.cfg.divid + "_";
135739
135865
 
135740
- this.REVISION = '3.51.0';
135866
+ this.REVISION = '3.51.1';
135741
135867
 
135742
135868
  // In nodejs, iCn3D defines "window = {navigator: {}}", and added window = {navigator: {}, "__THREE__":"177"}
135743
135869
  this.bNode = (Object.keys(window).length < 3) ? true : false;