|
@@ -61,12 +61,12 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
StringBuilder.writeSafe(this.out, `@<TRIPOS>SUBSTRUCTURE\n1 ${name} 1\n`);
|
|
|
}
|
|
|
|
|
|
- private count<K, V>(map: Map<K, V>, predicate: (k: K, v: V) => boolean): number {
|
|
|
+ private count<K, V, C>(map: Map<K, V>, ctx: C, predicate: (k: K, v: V, ctx: C) => boolean): number {
|
|
|
let count = 0;
|
|
|
const iter = map.entries();
|
|
|
let result = iter.next();
|
|
|
while (!result.done) {
|
|
|
- if (predicate(result.value[0], result.value[1])) {
|
|
|
+ if (predicate(result.value[0], result.value[1], ctx)) {
|
|
|
count++;
|
|
|
}
|
|
|
result = iter.next();
|
|
@@ -122,15 +122,15 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
return type_symbol1 + (numBonds <= 4 ? '.th' : '.oh');
|
|
|
}
|
|
|
if (type_symbol1 === 'C') {
|
|
|
- if (numBonds >= 4 && this.count(bonds, (_k, v) => v.order === 1) >= 4) return 'C.3';
|
|
|
+ if (numBonds >= 4 && this.count(bonds, this, (_k, v) => v.order === 1) >= 4) return 'C.3';
|
|
|
if (numBonds === 3 && this.isCat(bonds, bondMap)) return 'C.cat';
|
|
|
- if (numBonds >= 2 && this.count(bonds, (_k, v) => BondType.is(BondType.Flag.Aromatic, v.flags)) >= 2) return 'C.ar';
|
|
|
- if ((numBonds === 1 || numBonds === 2) && this.count(bonds, (_k, v) => v.order === 3)) return 'C.1'; // 1.6.4, 3i04/ligand?encoding=mol2&auth_asym_id=C&auth_seq_id=900 (CYN)
|
|
|
+ if (numBonds >= 2 && this.count(bonds, this, (_k, v) => BondType.is(BondType.Flag.Aromatic, v.flags)) >= 2) return 'C.ar';
|
|
|
+ if ((numBonds === 1 || numBonds === 2) && this.count(bonds, this, (_k, v) => v.order === 3)) return 'C.1'; // 1.6.4, 3i04/ligand?encoding=mol2&auth_asym_id=C&auth_seq_id=900 (CYN)
|
|
|
return 'C.2';
|
|
|
}
|
|
|
|
|
|
|
|
|
- const nonmets = this.count(bonds, (k, _v) => this.isNonMetalBond(k)) === bonds.size ? bonds : this.extractNonmets(bonds);
|
|
|
+ const nonmets = this.count(bonds, this, (k, _v, ctx) => ctx.isNonMetalBond(k)) === bonds.size ? bonds : this.extractNonmets(bonds);
|
|
|
const numNonmets = nonmets.size;
|
|
|
|
|
|
if (type_symbol1 === 'O') {
|
|
@@ -138,18 +138,18 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
if (this.isOC(nonmets, bondMap)) return 'O.co2';
|
|
|
if (this.isOP(nonmets, bondMap)) return 'O.co2';
|
|
|
}
|
|
|
- if (numNonmets >= 2 && this.count(bonds, (_k, v) => v.order === 1) === bonds.size) return 'O.3';
|
|
|
+ if (numNonmets >= 2 && this.count(bonds, this, (_k, v) => v.order === 1) === bonds.size) return 'O.3';
|
|
|
return 'O.2';
|
|
|
}
|
|
|
if (type_symbol1 === 'N') {
|
|
|
- if (numNonmets === 4 && this.count(nonmets, (_k, v) => v.order === 1) === 4) return 'N.4';
|
|
|
- if (numBonds >= 2 && this.count(bonds, (_k, v) => BondType.is(BondType.Flag.Aromatic, v.flags)) >= 2) return 'N.ar';
|
|
|
- if (numNonmets === 1 && this.count(nonmets, (_k, v) => v.order === 3)) return 'N.1';
|
|
|
+ if (numNonmets === 4 && this.count(nonmets, this, (_k, v) => v.order === 1) === 4) return 'N.4';
|
|
|
+ if (numBonds >= 2 && this.count(bonds, this, (_k, v) => BondType.is(BondType.Flag.Aromatic, v.flags)) >= 2) return 'N.ar';
|
|
|
+ if (numNonmets === 1 && this.count(nonmets, this, (_k, v) => v.order === 3)) return 'N.1';
|
|
|
if (numNonmets === 2 && this.orderSum(nonmets) === 4) return 'N.1';
|
|
|
if (numNonmets === 3 && this.hasCOCS(nonmets, bondMap)) return 'N.am';
|
|
|
if (numNonmets === 3) {
|
|
|
- if (this.count(nonmets, (_k, v) => v.order > 1) === 1) return 'N.pl3';
|
|
|
- if (this.count(nonmets, (_k, v) => v.order === 1) === 3) {
|
|
|
+ if (this.count(nonmets, this, (_k, v) => v.order > 1) === 1) return 'N.pl3';
|
|
|
+ if (this.count(nonmets, this, (_k, v) => v.order === 1) === 3) {
|
|
|
if (this.isNpl3(nonmets, bondMap)) return 'N.pl3';
|
|
|
}
|
|
|
return 'N.3';
|
|
@@ -159,7 +159,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
if (type_symbol1 === 'S') {
|
|
|
if (numNonmets === 3 && this.countOfOxygenWithSingleNonmet(nonmets, bondMap) === 1) return 'S.o';
|
|
|
if (numNonmets === 4 && this.countOfOxygenWithSingleNonmet(nonmets, bondMap) === 2) return 'S.o2';
|
|
|
- if (numNonmets >= 2 && this.count(bonds, (_k, v) => v.order === 1) >= 2) return 'S.3';
|
|
|
+ if (numNonmets >= 2 && this.count(bonds, this, (_k, v) => v.order === 1) >= 2) return 'S.3';
|
|
|
return 'S.2';
|
|
|
}
|
|
|
return type_symbol1;
|
|
@@ -176,7 +176,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
while (!result.done) {
|
|
|
const label_atom_id = result.value;
|
|
|
const adjacentBonds = bondMap.map.get(label_atom_id)!;
|
|
|
- if (this.count(adjacentBonds, (_k, v) => v.order > 1 || BondType.is(BondType.Flag.Aromatic, v.flags))) {
|
|
|
+ if (this.count(adjacentBonds, this, (_k, v) => v.order > 1 || BondType.is(BondType.Flag.Aromatic, v.flags))) {
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -200,7 +200,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
const label_atom_id = result.value;
|
|
|
if (label_atom_id.startsWith('O')) {
|
|
|
const adjacentBonds = bondMap.map.get(label_atom_id)!;
|
|
|
- if (this.count(adjacentBonds, (k, _v) => this.isNonMetalBond(k)) === 1) count++;
|
|
|
+ if (this.count(adjacentBonds, this, (k, _v, ctx) => ctx.isNonMetalBond(k)) === 1) count++;
|
|
|
}
|
|
|
result = iter.next();
|
|
|
}
|
|
@@ -222,7 +222,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
const label_atom_id = result.value;
|
|
|
if (label_atom_id.startsWith('O')) {
|
|
|
const adjacentBonds = bondMap.map.get(label_atom_id)!;
|
|
|
- if (this.count(adjacentBonds, (k, _v) => this.isNonMetalBond(k)) === 1) count++;
|
|
|
+ if (this.count(adjacentBonds, this, (k, _v, ctx) => ctx.isNonMetalBond(k)) === 1) count++;
|
|
|
}
|
|
|
result = iter.next();
|
|
|
}
|
|
@@ -261,7 +261,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
const label_atom_id = result.value;
|
|
|
if (label_atom_id.startsWith('O')) {
|
|
|
const adjacentBonds = bondMap.map.get(label_atom_id)!;
|
|
|
- if (this.count(adjacentBonds, (k, _v) => this.isNonMetalBond(k))) count++;
|
|
|
+ if (this.count(adjacentBonds, this, (k, _v, ctx) => ctx.isNonMetalBond(k))) count++;
|
|
|
}
|
|
|
result = iter.next();
|
|
|
}
|
|
@@ -276,7 +276,7 @@ export class Mol2Encoder extends LigandEncoder {
|
|
|
const label_atom_id = result.value;
|
|
|
if (label_atom_id.startsWith('C')) {
|
|
|
const adjacentBonds = bondMap.map.get(label_atom_id)!;
|
|
|
- if (this.count(adjacentBonds, (k, v) => k.startsWith('O') || k.startsWith('S') && v.order === 2)) return true;
|
|
|
+ if (this.count(adjacentBonds, this, (k, v) => k.startsWith('O') || k.startsWith('S') && v.order === 2)) return true;
|
|
|
}
|
|
|
result = iter.next();
|
|
|
}
|