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

add .uniqueElementCount and .polymerUnitCount to Structure

parent f8c9bc68
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,9 @@ class Structure { ...@@ -56,7 +56,9 @@ class Structure {
/** Hash based on all unit.id values in the structure, reflecting the units transformation */ /** Hash based on all unit.id values in the structure, reflecting the units transformation */
transformHash: number, transformHash: number,
elementCount: number, elementCount: number,
uniqueElementCount: number,
polymerResidueCount: number, polymerResidueCount: number,
polymerUnitCount: number,
coordinateSystem: SymmetryOperator, coordinateSystem: SymmetryOperator,
label: string, label: string,
propertyData?: any, propertyData?: any,
...@@ -65,7 +67,9 @@ class Structure { ...@@ -65,7 +67,9 @@ class Structure {
hashCode: -1, hashCode: -1,
transformHash: -1, transformHash: -1,
elementCount: -1, elementCount: -1,
uniqueElementCount: -1,
polymerResidueCount: -1, polymerResidueCount: -1,
polymerUnitCount: -1,
coordinateSystem: SymmetryOperator.Default, coordinateSystem: SymmetryOperator.Default,
label: '' label: ''
}; };
...@@ -106,15 +110,25 @@ class Structure { ...@@ -106,15 +110,25 @@ 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) { if (this._props.polymerResidueCount === -1) {
let polymerResidueCount = 0 this._props.polymerResidueCount = getPolymerResidueCount(this)
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;
} }
get polymerUnitCount() {
if (this._props.polymerUnitCount === -1) {
this._props.polymerUnitCount = getPolymerUnitCount(this)
}
return this._props.polymerUnitCount;
}
get uniqueElementCount() {
if (this._props.uniqueElementCount === -1) {
this._props.uniqueElementCount = getUniqueElementCount(this)
}
return this._props.uniqueElementCount;
}
/** Coarse structure, defined as Containing less than twice as many elements as polymer residues */ /** Coarse structure, defined as Containing less than twice as many elements as polymer residues */
get isCoarse() { get isCoarse() {
const ec = this.elementCount const ec = this.elementCount
...@@ -131,6 +145,7 @@ class Structure { ...@@ -131,6 +145,7 @@ class Structure {
return this.computeHash(); return this.computeHash();
} }
/** Hash based on all unit.id values in the structure, reflecting the units transformation */
get transformHash() { get transformHash() {
if (this._props.transformHash !== -1) return this._props.transformHash; if (this._props.transformHash !== -1) return this._props.transformHash;
this._props.transformHash = hashFnv32a(this.units.map(u => u.id)) this._props.transformHash = hashFnv32a(this.units.map(u => u.id))
...@@ -408,6 +423,33 @@ function getUniqueAtomicResidueIndices(structure: Structure): ReadonlyMap<UUID, ...@@ -408,6 +423,33 @@ function getUniqueAtomicResidueIndices(structure: Structure): ReadonlyMap<UUID,
return ret; return ret;
} }
function getUniqueElementCount(structure: Structure): number {
const { unitSymmetryGroups } = structure
let uniqueElementCount = 0
for (let i = 0, _i = unitSymmetryGroups.length; i < _i; i++) {
uniqueElementCount += unitSymmetryGroups[i].elements.length
}
return uniqueElementCount
}
function getPolymerResidueCount(structure: Structure): number {
const { units } = structure
let polymerResidueCount = 0
for (let i = 0, _i = units.length; i < _i; i++) {
polymerResidueCount += units[i].polymerElements.length;
}
return polymerResidueCount
}
function getPolymerUnitCount(structure: Structure): number {
const { units } = structure
let polymerUnitCount = 0
for (let i = 0, _i = units.length; i < _i; i++) {
if (units[i].polymerElements.length > 0) polymerUnitCount += 1
}
return polymerUnitCount
}
interface SerialMapping { interface SerialMapping {
/** Cummulative count of elements for each unit */ /** Cummulative count of elements for each unit */
unitElementCount: ArrayLike<number> unitElementCount: ArrayLike<number>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment