Browse Source

wip, interactions, various fixes

- limit bond-related calculations to covalent bonds
- wrong charge feature assignment
Alexander Rose 5 years ago
parent
commit
3601955433

+ 19 - 11
src/mol-model-props/computed/chemistry/util.ts

@@ -33,12 +33,22 @@ export function compId(unit: Unit.Atomic, index: StructureElement.UnitIndex) {
 //
 
 export function interBondCount(structure: Structure, unit: Unit.Atomic, index: StructureElement.UnitIndex): number {
-    return structure.interUnitBonds.getEdgeIndices(index, unit).length
+    let count = 0
+    const indices = structure.interUnitBonds.getEdgeIndices(index, unit)
+    for (let i = 0, il = indices.length; i < il; ++i) {
+        const b = structure.interUnitBonds.edges[indices[i]]
+        if (BondType.isCovalent(b.props.flag)) count += 1
+    }
+    return count
 }
 
 export function intraBondCount(unit: Unit.Atomic, index: StructureElement.UnitIndex): number {
-    const { offset } = unit.bonds
-    return offset[index + 1] - offset[index]
+    let count = 0
+    const { offset, edgeProps: { flags } } = unit.bonds
+    for (let i = offset[index], il = offset[index + 1]; i < il; ++i) {
+        if (BondType.isCovalent(flags[i])) count += 1
+    }
+    return count
 }
 
 export function bondCount(structure: Structure, unit: Unit.Atomic, index: StructureElement.UnitIndex): number {
@@ -76,19 +86,17 @@ export function connectedTo(structure: Structure, unitA: Unit.Atomic, indexA: St
 //
 
 export function eachInterBondedAtom(structure: Structure, unit: Unit.Atomic, index: StructureElement.UnitIndex, cb: (unit: Unit.Atomic, index: StructureElement.UnitIndex) => void): void {
-    // inter
-    const interIndices = structure.interUnitBonds.getEdgeIndices(index, unit)
-    for (let i = 0, il = interIndices.length; i < il; ++i) {
-        const b = structure.interUnitBonds.edges[i]
-        cb(b.unitB, b.indexB)
+    const indices = structure.interUnitBonds.getEdgeIndices(index, unit)
+    for (let i = 0, il = indices.length; i < il; ++i) {
+        const b = structure.interUnitBonds.edges[indices[i]]
+        if (BondType.isCovalent(b.props.flag)) cb(b.unitB, b.indexB)
     }
 }
 
 export function eachIntraBondedAtom(unit: Unit.Atomic, index: StructureElement.UnitIndex, cb: (unit: Unit.Atomic, index: StructureElement.UnitIndex) => void): void {
-    // intra
-    const { offset, b } = unit.bonds
+    const { offset, b, edgeProps: { flags } } = unit.bonds
     for (let i = offset[index], il = offset[index + 1]; i < il; ++i) {
-        cb(unit, b[i] as StructureElement.UnitIndex)
+        if (BondType.isCovalent(flags[i])) cb(unit, b[i] as StructureElement.UnitIndex)
     }
 }
 

+ 9 - 3
src/mol-model-props/computed/chemistry/valence-model.ts

@@ -13,6 +13,7 @@ import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 import { RuntimeContext } from '../../../mol-task';
 import { isDebugMode } from '../../../mol-util/debug';
 import { SortedArray } from '../../../mol-data/int';
+import { BondType } from '../../../mol-model/structure/model/types';
 
 /**
  * TODO:
@@ -67,10 +68,15 @@ function isConjugated (structure: Structure, unit: Unit.Atomic, index: Structure
 export function explicitValence (structure: Structure, unit: Unit.Atomic, index: StructureElement.UnitIndex) {
     let v = 0
     // intra-unit bonds
-    const { offset, edgeProps } = unit.bonds
-    for (let i = offset[index], il = offset[index + 1]; i < il; ++i) v += edgeProps.order[i]
+    const { offset, edgeProps: { flags, order } } = unit.bonds
+    for (let i = offset[index], il = offset[index + 1]; i < il; ++i) {
+        if (BondType.isCovalent(flags[i])) v += order[i]
+    }
     // inter-unit bonds
-    structure.interUnitBonds.getEdgeIndices(index, unit).forEach(b => v += structure.interUnitBonds.edges[b].props.order)
+    structure.interUnitBonds.getEdgeIndices(index, unit).forEach(i => {
+        const b = structure.interUnitBonds.edges[i]
+        if (BondType.isCovalent(b.props.flag)) v += b.props.order
+    })
     return v
 }
 

+ 2 - 2
src/mol-model-props/computed/interactions/charged.ts

@@ -154,7 +154,7 @@ function addUnitNegativeCharges(structure: Structure, unit: Unit.Atomic, builder
                 if (typeSymbol(unit, j) === Elements.N && !ProteinBackboneAtoms.has(atomId(unit, j))) {
                     builder.pushMember(x[elements[j]], y[elements[j]], z[elements[j]], j)
                 }
-                builder.finishState(FeatureType.PositiveCharge, FeatureGroup.None)
+                builder.finishState(FeatureType.NegativeCharge, FeatureGroup.None)
 
                 let group = FeatureGroup.None
                 if (isSulfonicAcid(structure, unit, j)) {
@@ -174,7 +174,7 @@ function addUnitNegativeCharges(structure: Structure, unit: Unit.Atomic, builder
                             builder.pushMember(x[elements[k]], y[elements[k]], z[elements[k]], k)
                         }
                     })
-                    builder.finishState(FeatureType.PositiveCharge, group)
+                    builder.finishState(FeatureType.NegativeCharge, group)
                 }
             }
 

+ 1 - 1
src/mol-model-props/computed/interactions/hydrogen-bonds.ts

@@ -139,7 +139,7 @@ function addUnitHydrogenAcceptors(structure: Structure, unit: Unit.Atomic, build
     const { elements } = unit
     const { x, y, z } = unit.model.atomicConformation
 
-    function add(i: StructureElement.UnitIndex) {
+    const add = (i: StructureElement.UnitIndex) => {
         builder.add(FeatureType.HydrogenAcceptor, FeatureGroup.None, x[elements[i]], y[elements[i]], z[elements[i]], i)
     }