From eb196a41b51bedbfe7a96c5d10eb171e04c753c4 Mon Sep 17 00:00:00 2001 From: ludovic autin <autin@scripps.edu> Date: Tue, 14 Sep 2021 11:25:15 -0700 Subject: [PATCH] change variables names to avoid confusion with other types. Added the xrayshading for the compartment geometry --- src/extensions/cellpack/data.ts | 16 ++++++++------ src/extensions/cellpack/model.ts | 38 ++++++++++++++++++-------------- src/extensions/cellpack/state.ts | 21 ++++++++++-------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/extensions/cellpack/data.ts b/src/extensions/cellpack/data.ts index f415040fc..6764ddc7f 100644 --- a/src/extensions/cellpack/data.ts +++ b/src/extensions/cellpack/data.ts @@ -15,13 +15,15 @@ export interface CellPacking { name: string, location: 'surface' | 'interior' | 'cytoplasme' ingredients: Packing['ingredients'] + compartment?: CellCompartment +} + +export interface CellCompartment { filename?: string geom_type?: 'raw' | 'file' | 'sphere' | 'mb' | 'None' - primitives?: Primitives + compartment_primitives?: CompartmentPrimitives } -// - export interface Cell { recipe: Recipe options?: RecipeOptions @@ -46,11 +48,11 @@ export interface Compartment { interior?: Packing geom?: unknown geom_type?: 'raw' | 'file' | 'sphere' | 'mb' | 'None' - mb?: Primitives + mb?: CompartmentPrimitives } // Primitives discribing a compartment -export const enum PrimitiveType { +export const enum CompartmentPrimitiveType { MetaBall = 0, Sphere = 1, Cube = 2, @@ -60,10 +62,10 @@ export const enum PrimitiveType { None = 6 } -export interface Primitives{ +export interface CompartmentPrimitives{ positions?: number[]; radii?: number[]; - types?: PrimitiveType[]; + types?: CompartmentPrimitiveType[]; } diff --git a/src/extensions/cellpack/model.ts b/src/extensions/cellpack/model.ts index 1a55ed03f..5715ce080 100644 --- a/src/extensions/cellpack/model.ts +++ b/src/extensions/cellpack/model.ts @@ -9,7 +9,7 @@ import { StateAction, StateBuilder, StateTransformer, State } from '../../mol-st import { PluginContext } from '../../mol-plugin/context'; import { PluginStateObject as PSO } from '../../mol-plugin-state/objects'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; -import { Ingredient, CellPacking, Primitives } from './data'; +import { Ingredient, CellPacking, CompartmentPrimitives } from './data'; import { getFromPdb, getFromCellPackDB, IngredientFiles, parseCif, parsePDBfile, getStructureMean, getFromOPM } from './util'; import { Model, Structure, StructureSymmetry, StructureSelection, QueryContext, Unit, Trajectory } from '../../mol-model/structure'; import { trajectoryFromMmCIF, MmcifFormat } from '../../mol-model-formats/structure/mmcif'; @@ -31,6 +31,7 @@ import { Asset } from '../../mol-util/assets'; import { Color } from '../../mol-util/color'; import { objectForEach } from '../../mol-util/object'; import { readFromFile } from '../../mol-util/data-source'; +import { ColorNames } from '../../mol-util/color/names'; function getCellPackModelUrl(fileName: string, baseUrl: string) { return `${baseUrl}/results/${fileName}`; @@ -524,7 +525,8 @@ async function loadMembrane(plugin: PluginContext, name: string, state: State, p } else if (geometry_membrane) { await b.apply(StateTransforms.Data.ParsePly, undefined, { state: { isGhost: true } }) .apply(StateTransforms.Model.ShapeFromPly) - .apply(StateTransforms.Representation.ShapeRepresentation3D) + .apply(StateTransforms.Representation.ShapeRepresentation3D, { xrayShaded: true, + doubleSided: true, coloring: { name: 'uniform', params: { color: ColorNames.orange } } }) .commit({ revertOnError: true }); } else { const membrane = await b.apply(StateTransforms.Data.ParseCif, undefined, { state: { isGhost: true } }) @@ -539,7 +541,7 @@ async function loadMembrane(plugin: PluginContext, name: string, state: State, p } } -async function handleMembraneSpheres(state: State, primitives: Primitives) { +async function handleMembraneSpheres(state: State, primitives: CompartmentPrimitives) { const nSpheres = primitives.positions!.length / 3; // console.log('ok mb ', nSpheres); // TODO : take in account the type of the primitives. @@ -619,16 +621,14 @@ async function loadPackings(plugin: PluginContext, runtime: RuntimeContext, stat representation: params.preset.representation, }; await CellpackPackingPreset.apply(packing, packingParams, plugin); - if (packings[i].location === 'surface') { - // console.log('ok surface ' + params.membrane); + if (packings[i].compartment) { if (params.membrane === 'lipids') { - // console.log('ok packings[i].geom_type ' + packings[i].geom_type); - if (packings[i].geom_type) { - if (packings[i].geom_type === 'file') { + if (packings[i].compartment!.geom_type) { + if (packings[i].compartment!.geom_type === 'file') { // TODO: load mesh files or vertex,faces data - await loadMembrane(plugin, packings[i].filename!, state, params); - } else if (packings[i].primitives) { - await handleMembraneSpheres(state, packings[i].primitives!); + await loadMembrane(plugin, packings[i].compartment!.filename!, state, params); + } else if (packings[i].compartment!.compartment_primitives) { + await handleMembraneSpheres(state, packings[i].compartment!.compartment_primitives!); } } else { // try loading membrane from repo as a bcif file or from the given list of files. @@ -636,9 +636,13 @@ async function loadPackings(plugin: PluginContext, runtime: RuntimeContext, stat await loadMembrane(plugin, packings[i].name, state, params); } } - } else if (params.membrane === 'spheres') { - if (packings[i].primitives) { - await handleMembraneSpheres(state, packings[i].primitives!); + } else if (params.membrane === 'geometry') { + if (packings[i].compartment!.compartment_primitives) { + await handleMembraneSpheres(state, packings[i].compartment!.compartment_primitives!); + } else if (packings[i].compartment!.geom_type === 'file') { + if (packings[i].compartment!.filename!.toLowerCase().endsWith('.ply')) { + await loadMembrane(plugin, packings[i].compartment!.filename!, state, params); + } } } } @@ -650,10 +654,10 @@ const LoadCellPackModelParams = { 'id': PD.Select('InfluenzaModel2.json', [ ['blood_hiv_immature_inside.json', 'Blood HIV immature'], ['HIV_immature_model.json', 'HIV immature'], - ['BloodHIV1.0_mixed_fixed_nc1.cpr', 'Blood HIV'], + ['Blood_HIV.json', 'Blood HIV'], ['HIV-1_0.1.6-8_mixed_radii_pdb.json', 'HIV'], ['influenza_model1.json', 'Influenza envelope'], - ['InfluenzaModel2.json', 'Influenza Complete'], + ['InfluenzaModel2.json', 'Influenza complete'], ['ExosomeModel.json', 'Exosome Model'], ['MycoplasmaGenitalium.json', 'Mycoplasma Genitalium curated model'], ] as const, { description: 'Download the model definition with `id` from the server at `baseUrl.`' }), @@ -661,7 +665,7 @@ const LoadCellPackModelParams = { }, { options: [['id', 'Id'], ['file', 'File']] }), baseUrl: PD.Text(DefaultCellPackBaseUrl), results: PD.File({ accept: '.bin', description: 'open results file in binary format from cellpackgpu for the specified recipe', label: 'Results file' }), - membrane: PD.Select('lipids', PD.arrayToOptions(['lipids', 'spheres', 'none'])), + membrane: PD.Select('lipids', PD.arrayToOptions(['lipids', 'geometry', 'none'])), ingredients: PD.FileList({ accept: '.cif,.bcif,.pdb', label: 'Ingredient files' }), preset: PD.Group({ traceOnly: PD.Boolean(false), diff --git a/src/extensions/cellpack/state.ts b/src/extensions/cellpack/state.ts index 948f0e0cb..c06979fad 100644 --- a/src/extensions/cellpack/state.ts +++ b/src/extensions/cellpack/state.ts @@ -66,12 +66,13 @@ const ParseCellPack = PluginStateTransform.BuiltIn({ if (compartments) { for (const name in compartments) { const { surface, interior } = compartments[name]; + let filename = ''; + if (compartments[name].geom_type === 'file') { + filename = (compartments[name].geom) ? compartments[name].geom as string : ''; + } + const compartment = { filename: filename, geom_type: compartments[name].geom_type, compartment_primitives: compartments[name].mb }; if (surface) { - let filename = ''; - if (compartments[name].geom_type === 'file') { - filename = (compartments[name].geom) ? compartments[name].geom as string : ''; - } - packings.push({ name, location: 'surface', ingredients: surface.ingredients, filename: filename, geom_type: compartments[name].geom_type, primitives: compartments[name].mb }); + packings.push({ name, location: 'surface', ingredients: surface.ingredients, compartment: compartment }); for (const iName in surface.ingredients) { if (surface.ingredients[iName].ingtype === 'fiber') { cell.mapping_ids[-(fiber_counter_id + 1)] = [comp_counter, iName]; @@ -86,7 +87,8 @@ const ParseCellPack = PluginStateTransform.BuiltIn({ comp_counter++; } if (interior) { - packings.push({ name, location: 'interior', ingredients: interior.ingredients }); + if (!surface) packings.push({ name, location: 'interior', ingredients: interior.ingredients, compartment: compartment }); + else packings.push({ name, location: 'interior', ingredients: interior.ingredients }); for (const iName in interior.ingredients) { if (interior.ingredients[iName].ingtype === 'fiber') { cell.mapping_ids[-(fiber_counter_id + 1)] = [comp_counter, iName]; @@ -306,7 +308,8 @@ export const CreateCompartmentSphere = CreateTransformer({ to: PSO.Shape.Representation3D, params: { center: PD.Vec3(Vec3()), - radius: PD.Numeric(1) + radius: PD.Numeric(1), + label: PD.Text(`Compartment Sphere`) } })({ canAutoUpdate({ oldParams, newParams }) { @@ -316,8 +319,8 @@ export const CreateCompartmentSphere = CreateTransformer({ return Task.create('Compartment Sphere', async ctx => { const data = params; const repr = MBRepresentation({ webgl: plugin.canvas3d?.webgl, ...plugin.representation.structure.themes }, () => (MBParams)); - await repr.createOrUpdate({ ...params, quality: 'custom', doubleSided: true }, data).runInContext(ctx); - return new PSO.Shape.Representation3D({ repr, sourceData: a }, { label: `Compartment Sphere` }); + await repr.createOrUpdate({ ...params, quality: 'custom', xrayShaded: true, doubleSided: true }, data).runInContext(ctx); + return new PSO.Shape.Representation3D({ repr, sourceData: a }, { label: data.label }); }); } }); \ No newline at end of file -- GitLab