Browse Source

mol-model: added findAtomOnResidue

David Sehnal 6 years ago
parent
commit
b0965642ec

+ 8 - 1
src/mol-model/structure/model/properties/atomic/hierarchy.ts

@@ -169,7 +169,14 @@ export interface AtomicIndex {
      * @param key
      * @returns index or -1 if the atom is not present.
      */
-    findAtomAuth(key: AtomicIndex.AtomAuthKey): ElementIndex
+    findAtomAuth(key: AtomicIndex.AtomAuthKey): ElementIndex,
+
+    /**
+     * Find element index of an atom on a given residue.
+     * @param key
+     * @returns index or -1 if the atom is not present.
+     */
+    findAtomOnResidue(residueIndex: ResidueIndex, label_atom_id: string, label_alt_id?: string): ElementIndex
 
     // TODO: add indices that support comp_id?
 }

+ 8 - 0
src/mol-model/structure/model/properties/utils/atomic-index.ts

@@ -152,6 +152,14 @@ class Index implements AtomicIndex {
         return findAtomByNameAndAltLoc(offsets[rI], offsets[rI + 1], this.map.auth_atom_id, this.map.label_alt_id, key.auth_atom_id, key.label_alt_id);
     }
 
+    findAtomOnResidue(rI: ResidueIndex, label_atom_id: string, label_alt_id?: string) {
+        const offsets = this.map.segments.residueAtomSegments.offsets;
+        if (typeof label_alt_id === 'undefined') {
+            return findAtomByName(offsets[rI], offsets[rI + 1], this.map.label_atom_id, label_atom_id);
+        }
+        return findAtomByNameAndAltLoc(offsets[rI], offsets[rI + 1], this.map.label_atom_id, this.map.label_alt_id, label_atom_id, label_alt_id);
+    }
+
     constructor(private map: Mapping) {
         this.entityIndex = map.entities.getEntityIndex;
     }