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

ensure SecondaryStructure is available

parent 39dbfbb6
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import { parseMolScript } from 'mol-script/language/parser';
import { transpileMolScript } from 'mol-script/script/mol-script/symbols';
import { compile } from 'mol-script/runtime/query/compiler';
import { Transparency } from 'mol-theme/transparency';
import { ComputedSecondaryStructure } from 'mol-model-props/computed/secondary-structure';
type Script = { language: string, expression: string }
......@@ -35,4 +36,15 @@ export function getStructureOverpaint(structure: Structure, scriptLayers: { scri
export function getStructureTransparency(structure: Structure, script: Script, value: number, variant: Transparency.Variant): Transparency {
return { loci: scriptToLoci(structure, script), value, variant }
}
/**
* Attaches ComputedSecondaryStructure property when unavailable in sourceData
*/
export async function ensureSecondaryStructure(s: Structure) {
if (s.model.sourceData.kind === 'mmCIF') {
if (!s.model.sourceData.data.struct_conf.id.isDefined && !s.model.sourceData.data.struct_sheet_range.id.isDefined) {
await ComputedSecondaryStructure.attachFromCifOrCompute(s)
}
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ import { parseMolScript } from 'mol-script/language/parser';
import { transpileMolScript } from 'mol-script/script/mol-script/symbols';
import { shapeFromPly } from 'mol-model-formats/shape/ply';
import { SymmetryOperator } from 'mol-math/geometry';
import { ensureSecondaryStructure } from './helpers';
export { TrajectoryFromBlob };
export { TrajectoryFromMmCif };
......@@ -167,9 +168,12 @@ const StructureFromModel = PluginStateTransform.BuiltIn({
to: SO.Molecule.Structure
})({
apply({ a }) {
let s = Structure.ofModel(a.data);
const props = { label: a.data.label, description: s.elementCount === 1 ? '1 element' : `${s.elementCount} elements` };
return new SO.Molecule.Structure(s, props);
return Task.create('Build Structure', async ctx => {
const s = Structure.ofModel(a.data);
await ensureSecondaryStructure(s)
const props = { label: a.data.label, description: s.elementCount === 1 ? '1 element' : `${s.elementCount} elements` };
return new SO.Molecule.Structure(s, props);
})
}
});
......@@ -218,12 +222,14 @@ const StructureAssemblyFromModel = PluginStateTransform.BuiltIn({
const base = Structure.ofModel(model);
if (!asm) {
await ensureSecondaryStructure(base)
const label = { label: a.data.label, description: structureDesc(base) };
return new SO.Molecule.Structure(base, label);
}
id = asm.id;
const s = await StructureSymmetry.buildAssembly(base, id!).runInContext(ctx);
await ensureSecondaryStructure(s)
const props = { label: `Assembly ${id}`, description: structureDesc(s) };
return new SO.Molecule.Structure(s, props);
})
......@@ -249,6 +255,7 @@ const StructureSymmetryFromModel = PluginStateTransform.BuiltIn({
const model = a.data;
const base = Structure.ofModel(model);
const s = await StructureSymmetry.buildSymmetryRange(base, ijkMin, ijkMax).runInContext(ctx);
await ensureSecondaryStructure(s)
const props = { label: `Symmetry [${ijkMin}] to [${ijkMax}]`, description: structureDesc(s) };
return new SO.Molecule.Structure(s, props);
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment