Skip to content
Snippets Groups Projects
Commit 0ce2966c authored by Alexander Rose's avatar Alexander Rose
Browse files

lazy calculation of Structure.polymerResidueCount

parent f2c04a13
Branches
Tags
No related merge requests found
...@@ -64,8 +64,8 @@ class Structure { ...@@ -64,8 +64,8 @@ class Structure {
} = { } = {
hashCode: -1, hashCode: -1,
transformHash: -1, transformHash: -1,
elementCount: 0, elementCount: -1,
polymerResidueCount: 0, polymerResidueCount: -1,
coordinateSystem: SymmetryOperator.Default, coordinateSystem: SymmetryOperator.Default,
label: '' label: ''
}; };
...@@ -105,6 +105,13 @@ class Structure { ...@@ -105,6 +105,13 @@ class Structure {
/** Count of all polymer residues in the structure */ /** Count of all polymer residues in the structure */
get polymerResidueCount() { get polymerResidueCount() {
if (this._props.polymerResidueCount === -1) {
let polymerResidueCount = 0
for (let i = 0, _i = this.units.length; i < _i; i++) {
polymerResidueCount += this.units[i].polymerElements.length;
}
this._props.polymerResidueCount = polymerResidueCount
}
return this._props.polymerResidueCount; return this._props.polymerResidueCount;
} }
...@@ -269,21 +276,19 @@ class Structure { ...@@ -269,21 +276,19 @@ class Structure {
} }
getModelIndex(m: Model) { getModelIndex(m: Model) {
return this.model return this.models.indexOf(m)
} }
private initUnits(units: ArrayLike<Unit>) { private initUnits(units: ArrayLike<Unit>) {
const unitMap = IntMap.Mutable<Unit>(); const unitMap = IntMap.Mutable<Unit>();
const unitIndexMap = IntMap.Mutable<number>(); const unitIndexMap = IntMap.Mutable<number>();
let elementCount = 0; let elementCount = 0;
let polymerResidueCount = 0;
let isSorted = true; let isSorted = true;
let lastId = units.length > 0 ? units[0].id : 0; let lastId = units.length > 0 ? units[0].id : 0;
for (let i = 0, _i = units.length; i < _i; i++) { for (let i = 0, _i = units.length; i < _i; i++) {
const u = units[i]; const u = units[i];
unitMap.set(u.id, u); unitMap.set(u.id, u);
elementCount += u.elements.length; elementCount += u.elements.length;
polymerResidueCount += u.polymerElements.length;
if (u.id < lastId) isSorted = false; if (u.id < lastId) isSorted = false;
lastId = u.id; lastId = u.id;
} }
...@@ -292,7 +297,6 @@ class Structure { ...@@ -292,7 +297,6 @@ class Structure {
unitIndexMap.set(units[i].id, i); unitIndexMap.set(units[i].id, i);
} }
this._props.elementCount = elementCount; this._props.elementCount = elementCount;
this._props.polymerResidueCount = polymerResidueCount;
return { unitMap, unitIndexMap }; return { unitMap, unitIndexMap };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment