model.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /**
  2. * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { StateAction, StateBuilder, StateTransformer, State } from '../../../../mol-state';
  7. import { PluginContext } from '../../../../mol-plugin/context';
  8. import { PluginStateObject as PSO } from '../../../../mol-plugin-state/objects';
  9. import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
  10. import { Ingredient, IngredientSource, CellPacking } from './data';
  11. import { getFromPdb, getFromCellPackDB, IngredientFiles, parseCif, parsePDBfile } from './util';
  12. import { Model, Structure, StructureSymmetry, StructureSelection, QueryContext, Unit } from '../../../../mol-model/structure';
  13. import { trajectoryFromMmCIF, MmcifFormat } from '../../../../mol-model-formats/structure/mmcif';
  14. import { trajectoryFromPDB } from '../../../../mol-model-formats/structure/pdb';
  15. import { Mat4, Vec3, Quat } from '../../../../mol-math/linear-algebra';
  16. import { SymmetryOperator } from '../../../../mol-math/geometry';
  17. import { Task, RuntimeContext } from '../../../../mol-task';
  18. import { StateTransforms } from '../../../../mol-plugin-state/transforms';
  19. import { ParseCellPack, StructureFromCellpack, DefaultCellPackBaseUrl } from './state';
  20. import { MolScriptBuilder as MS } from '../../../../mol-script/language/builder';
  21. import { getMatFromResamplePoints } from './curve';
  22. import { compile } from '../../../../mol-script/runtime/query/compiler';
  23. import { CifCategory, CifField } from '../../../../mol-io/reader/cif';
  24. import { mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif';
  25. import { Column } from '../../../../mol-data/db';
  26. import { createModels } from '../../../../mol-model-formats/structure/basic/parser';
  27. import { CellpackPackingPreset, CellpackMembranePreset } from './preset';
  28. import { AjaxTask } from '../../../../mol-util/data-source';
  29. import { CellPackInfoProvider } from './property';
  30. import { CellPackColorThemeProvider } from './color';
  31. function getCellPackModelUrl(fileName: string, baseUrl: string) {
  32. return `${baseUrl}/results/${fileName}`
  33. }
  34. async function getModel(id: string, model_id: number, baseUrl: string, file?: File) {
  35. let model: Model;
  36. if (file) {
  37. const text = await file.text()
  38. if (file.name.endsWith('.cif')) {
  39. const cif = (await parseCif(text)).blocks[0]
  40. model = (await trajectoryFromMmCIF(cif).run())[model_id]
  41. } else if (file.name.endsWith('.pdb')) {
  42. const pdb = await parsePDBfile(text, id)
  43. model = (await trajectoryFromPDB(pdb).run())[model_id]
  44. } else {
  45. throw new Error(`unsupported file type '${file.name}'`)
  46. }
  47. } else if (id.match(/^[1-9][a-zA-Z0-9]{3,3}$/i)) {
  48. // return
  49. const cif = await getFromPdb(id)
  50. model = (await trajectoryFromMmCIF(cif).run())[model_id]
  51. } else {
  52. const pdb = await getFromCellPackDB(id, baseUrl)
  53. model = (await trajectoryFromPDB(pdb).run())[model_id]
  54. }
  55. return model
  56. }
  57. async function getStructure(model: Model, source: IngredientSource, props: { assembly?: string } = {}) {
  58. let structure = Structure.ofModel(model)
  59. const { assembly } = props
  60. if (assembly) {
  61. structure = await StructureSymmetry.buildAssembly(structure, assembly).run()
  62. }
  63. let query;
  64. if (source.selection){
  65. const asymIds:string[] = source.selection.replace(" :","").split(" or")
  66. query = MS.struct.modifier.union([
  67. MS.struct.generator.atomGroups({
  68. 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer']),
  69. 'chain-test': MS.core.set.has([MS.set(...asymIds), MS.ammp('auth_asym_id')])
  70. })
  71. ])
  72. }
  73. else {
  74. query = MS.struct.modifier.union([
  75. MS.struct.generator.atomGroups({
  76. 'entity-test': MS.core.rel.eq([MS.ammp('entityType'), 'polymer'])
  77. })
  78. ])
  79. }
  80. const compiled = compile<StructureSelection>(query)
  81. const result = compiled(new QueryContext(structure))
  82. structure = StructureSelection.unionStructure(result)
  83. return structure
  84. }
  85. function getTransformLegacy(trans: Vec3, rot: Quat) {
  86. const q: Quat = Quat.create(-rot[3], rot[0], rot[1], rot[2])
  87. const m: Mat4 = Mat4.fromQuat(Mat4.zero(), q)
  88. Mat4.transpose(m, m)
  89. Mat4.scale(m, m, Vec3.create(-1.0, 1.0, -1.0))
  90. Mat4.setTranslation(m, trans)
  91. return m
  92. }
  93. function getTransform(trans: Vec3, rot: Quat) {
  94. const q: Quat = Quat.create(rot[0], rot[1], rot[2], rot[3])
  95. const m: Mat4 = Mat4.fromQuat(Mat4.zero(), q)
  96. const p: Vec3 = Vec3.create(trans[0],trans[1],trans[2])
  97. Mat4.setTranslation(m, p)
  98. return m
  99. }
  100. function getResultTransforms(results: Ingredient['results'],legacy:boolean) {
  101. if (legacy) return results.map((r: Ingredient['results'][0]) => getTransformLegacy(r[0], r[1]))
  102. else return results.map((r: Ingredient['results'][0]) => getTransform(r[0], r[1]))
  103. }
  104. function getCurveTransforms(ingredient: Ingredient) {
  105. const n = ingredient.nbCurve || 0
  106. const instances: Mat4[] = []
  107. const segmentLength = (ingredient.radii)? ((ingredient.radii[0].radii)?ingredient.radii[0].radii[0]*2.0:3.4):3.4;
  108. for (let i = 0; i < n; ++i) {
  109. const cname = `curve${i}`
  110. if (!(cname in ingredient)) {
  111. // console.warn(`Expected '${cname}' in ingredient`)
  112. continue
  113. }
  114. const _points = ingredient[cname] as Vec3[]
  115. if (_points.length <= 2) {
  116. // TODO handle curve with 2 or less points
  117. continue
  118. }
  119. const points = new Float32Array(_points.length * 3)
  120. for (let i = 0, il = _points.length; i < il; ++i) Vec3.toArray(_points[i], points, i * 3)
  121. const newInstances = getMatFromResamplePoints(points,segmentLength)
  122. instances.push(...newInstances)
  123. }
  124. return instances
  125. }
  126. function getAssembly(transforms: Mat4[], structure: Structure) {
  127. const builder = Structure.Builder()
  128. const { units } = structure;
  129. for (let i = 0, il = transforms.length; i < il; ++i) {
  130. const id = `${i + 1}`
  131. const op = SymmetryOperator.create(id, transforms[i], { assembly: { id, operId: i, operList: [ id ] } })
  132. for (const unit of units) {
  133. builder.addWithOperator(unit, op)
  134. }
  135. }
  136. return builder.getStructure();
  137. }
  138. function getCifCurve(name: string, transforms: Mat4[], model: Model) {
  139. if (!MmcifFormat.is(model.sourceData)) throw new Error('mmcif source data needed')
  140. const { db } = model.sourceData.data
  141. const d = db.atom_site
  142. const n = d._rowCount
  143. const rowCount = n * transforms.length
  144. const { offsets, count } = model.atomicHierarchy.chainAtomSegments
  145. const x = d.Cartn_x.toArray()
  146. const y = d.Cartn_y.toArray()
  147. const z = d.Cartn_z.toArray()
  148. const Cartn_x = new Float32Array(rowCount)
  149. const Cartn_y = new Float32Array(rowCount)
  150. const Cartn_z = new Float32Array(rowCount)
  151. const map = new Uint32Array(rowCount)
  152. const seq = new Int32Array(rowCount)
  153. let offset = 0
  154. for (let c = 0; c < count; ++c) {
  155. const cStart = offsets[c]
  156. const cEnd = offsets[c + 1]
  157. const cLength = cEnd - cStart
  158. for (let t = 0, tl = transforms.length; t < tl; ++t) {
  159. const m = transforms[t]
  160. for (let j = cStart; j < cEnd; ++j) {
  161. const i = offset + j - cStart
  162. const xj = x[j], yj = y[j], zj = z[j]
  163. Cartn_x[i] = m[0] * xj + m[4] * yj + m[8] * zj + m[12]
  164. Cartn_y[i] = m[1] * xj + m[5] * yj + m[9] * zj + m[13]
  165. Cartn_z[i] = m[2] * xj + m[6] * yj + m[10] * zj + m[14]
  166. map[i] = j
  167. seq[i] = t + 1
  168. }
  169. offset += cLength
  170. }
  171. }
  172. function multColumn<T>(column: Column<T>) {
  173. const array = column.toArray()
  174. return Column.ofLambda({
  175. value: row => array[map[row]],
  176. areValuesEqual: (rowA, rowB) => map[rowA] === map[rowB] || array[map[rowA]] === array[map[rowB]],
  177. rowCount, schema: column.schema
  178. })
  179. }
  180. const _atom_site: CifCategory.SomeFields<mmCIF_Schema['atom_site']> = {
  181. auth_asym_id: CifField.ofColumn(multColumn(d.auth_asym_id)),
  182. auth_atom_id: CifField.ofColumn(multColumn(d.auth_atom_id)),
  183. auth_comp_id: CifField.ofColumn(multColumn(d.auth_comp_id)),
  184. auth_seq_id: CifField.ofNumbers(seq),
  185. B_iso_or_equiv: CifField.ofColumn(Column.ofConst(0, rowCount, Column.Schema.float)),
  186. Cartn_x: CifField.ofNumbers(Cartn_x),
  187. Cartn_y: CifField.ofNumbers(Cartn_y),
  188. Cartn_z: CifField.ofNumbers(Cartn_z),
  189. group_PDB: CifField.ofColumn(Column.ofConst('ATOM', rowCount, Column.Schema.str)),
  190. id: CifField.ofColumn(Column.ofLambda({
  191. value: row => row,
  192. areValuesEqual: (rowA, rowB) => rowA === rowB,
  193. rowCount, schema: d.id.schema,
  194. })),
  195. label_alt_id: CifField.ofColumn(multColumn(d.label_alt_id)),
  196. label_asym_id: CifField.ofColumn(multColumn(d.label_asym_id)),
  197. label_atom_id: CifField.ofColumn(multColumn(d.label_atom_id)),
  198. label_comp_id: CifField.ofColumn(multColumn(d.label_comp_id)),
  199. label_seq_id: CifField.ofNumbers(seq),
  200. label_entity_id: CifField.ofColumn(Column.ofConst('1', rowCount, Column.Schema.str)),
  201. occupancy: CifField.ofColumn(Column.ofConst(1, rowCount, Column.Schema.float)),
  202. type_symbol: CifField.ofColumn(multColumn(d.type_symbol)),
  203. pdbx_PDB_ins_code: CifField.ofColumn(Column.ofConst('', rowCount, Column.Schema.str)),
  204. pdbx_PDB_model_num: CifField.ofColumn(Column.ofConst(1, rowCount, Column.Schema.int)),
  205. }
  206. const categories = {
  207. entity: CifCategory.ofTable('entity', db.entity),
  208. chem_comp: CifCategory.ofTable('chem_comp', db.chem_comp),
  209. atom_site: CifCategory.ofFields('atom_site', _atom_site)
  210. }
  211. return {
  212. header: name,
  213. categoryNames: Object.keys(categories),
  214. categories
  215. };
  216. }
  217. async function getCurve(name: string, ingredient:Ingredient, transforms: Mat4[], model: Model) {
  218. const cif = getCifCurve(name, transforms, model)
  219. const curveModelTask = Task.create('Curve Model', async ctx => {
  220. const format = MmcifFormat.fromFrame(cif)
  221. const models = await createModels(format.data.db, format, ctx)
  222. return models[0]
  223. })
  224. const curveModel = await curveModelTask.run()
  225. return getStructure(curveModel, ingredient.source)
  226. }
  227. async function getIngredientStructure(ingredient: Ingredient, baseUrl: string, ingredientFiles: IngredientFiles) {
  228. const { name, source, results, nbCurve } = ingredient
  229. if (source.pdb === 'None') return
  230. const file = ingredientFiles[source.pdb]
  231. if (!file) {
  232. // TODO can these be added to the library?
  233. if (name === 'HIV1_CAhex_0_1_0') return
  234. if (name === 'HIV1_CAhexCyclophilA_0_1_0') return
  235. if (name === 'iLDL') return
  236. if (name === 'peptides') return
  237. if (name === 'lypoglycane') return
  238. }
  239. //model id in case structure is NMR
  240. const model_id = (ingredient.source.model)? parseInt(ingredient.source.model) : 0;
  241. const model = await getModel(source.pdb || name,model_id, baseUrl, file)
  242. if (!model) return
  243. if (nbCurve) {
  244. return getCurve(name, ingredient, getCurveTransforms(ingredient), model)
  245. } else {
  246. let bu:string|undefined = source.bu ? source.bu : undefined;
  247. if (bu){
  248. if (bu === "AU") {bu = undefined;}
  249. else {
  250. bu = bu.slice(2)
  251. }
  252. }
  253. let structure = await getStructure(model,source, { assembly: bu })
  254. //transform with offset and pcp
  255. let legacy:boolean = true
  256. if (ingredient.offset || ingredient.principalAxis)
  257. //center the structure
  258. {
  259. legacy=false
  260. const boundary = structure.boundary
  261. let structureCenter:Vec3 = Vec3.zero()
  262. Vec3.negate(structureCenter,boundary.sphere.center)
  263. const m1: Mat4 = Mat4.identity()
  264. Mat4.setTranslation(m1, structureCenter)
  265. structure = Structure.transform(structure,m1)
  266. if (ingredient.offset)
  267. {
  268. if (!Vec3.exactEquals(ingredient.offset,Vec3.zero()))
  269. {
  270. const m: Mat4 = Mat4.identity();
  271. Mat4.setTranslation(m, ingredient.offset)
  272. structure = Structure.transform(structure,m);
  273. }
  274. }
  275. if (ingredient.principalAxis)
  276. {
  277. if (!Vec3.exactEquals(ingredient.principalAxis,Vec3.unitZ))
  278. {
  279. const q: Quat = Quat.identity();
  280. Quat.rotationTo(q,ingredient.principalAxis,Vec3.unitZ)
  281. const m: Mat4 = Mat4.fromQuat(Mat4.zero(), q)
  282. structure = Structure.transform(structure,m);
  283. }
  284. }
  285. }
  286. return getAssembly(getResultTransforms(results,legacy), structure)
  287. }
  288. }
  289. export function createStructureFromCellPack(packing: CellPacking, baseUrl: string, ingredientFiles: IngredientFiles) {
  290. return Task.create('Create Packing Structure', async ctx => {
  291. const { ingredients, name } = packing
  292. const structures: Structure[] = []
  293. for (const iName in ingredients) {
  294. if (ctx.shouldUpdate) await ctx.update(iName)
  295. const s = await getIngredientStructure(ingredients[iName], baseUrl, ingredientFiles)
  296. if (s) structures.push(s)
  297. }
  298. if (ctx.shouldUpdate) await ctx.update(`${name} - units`)
  299. const builder = Structure.Builder({ label: name })
  300. let offsetInvariantId = 0
  301. for (const s of structures) {
  302. if (ctx.shouldUpdate) await ctx.update(`${s.label}`)
  303. let maxInvariantId = 0
  304. for (const u of s.units) {
  305. const invariantId = u.invariantId + offsetInvariantId
  306. if (u.invariantId > maxInvariantId) maxInvariantId = u.invariantId
  307. builder.addUnit(u.kind, u.model, u.conformation.operator, u.elements, Unit.Trait.None, invariantId)
  308. }
  309. offsetInvariantId += maxInvariantId + 1
  310. }
  311. if (ctx.shouldUpdate) await ctx.update(`${name} - structure`)
  312. const s = builder.getStructure()
  313. for( let i = 0, il = s.models.length; i < il; ++i) {
  314. const { trajectoryInfo } = s.models[i]
  315. trajectoryInfo.size = il
  316. trajectoryInfo.index = i
  317. }
  318. return s
  319. })
  320. }
  321. async function handleHivRna(ctx: { runtime: RuntimeContext, fetch: AjaxTask }, packings: CellPacking[], baseUrl: string) {
  322. for (let i = 0, il = packings.length; i < il; ++i) {
  323. if (packings[i].name === 'HIV1_capsid_3j3q_PackInner_0_1_0') {
  324. const url = `${baseUrl}/extras/rna_allpoints.json`
  325. const data = await ctx.fetch({ url, type: 'string' }).runInContext(ctx.runtime);
  326. const { points } = await (new Response(data)).json() as { points: number[] }
  327. const curve0: Vec3[] = []
  328. for (let j = 0, jl = points.length; j < jl; j += 3) {
  329. curve0.push(Vec3.fromArray(Vec3(), points, j))
  330. }
  331. packings[i].ingredients['RNA'] = {
  332. source: { pdb: 'RNA_U_Base.pdb', transform: { center: false } },
  333. results: [],
  334. name: 'RNA',
  335. nbCurve: 1,
  336. curve0
  337. }
  338. }
  339. }
  340. }
  341. async function loadMembrane(name:string, plugin: PluginContext, runtime: RuntimeContext, state: State, params: LoadCellPackModelParams) {
  342. const fname: string = `${name}.bcif`
  343. let ingredientFiles: IngredientFiles = {}
  344. if (params.ingredients.files !== null) {
  345. for (let i = 0, il = params.ingredients.files.length; i < il; ++i) {
  346. const file = params.ingredients.files.item(i)
  347. if (file) ingredientFiles[file.name] = file
  348. }
  349. }
  350. const url = `${params.baseUrl}/membranes/${name}.bcif`
  351. //
  352. const file = (ingredientFiles)?ingredientFiles[fname]:null;
  353. let membrane
  354. if (!file)
  355. //can we check if url exist
  356. {
  357. membrane = await state.build().toRoot()
  358. .apply(StateTransforms.Data.Download, { label: name, url, isBinary: true }, { state: { isGhost: true } })
  359. .apply(StateTransforms.Data.ParseCif, undefined, { state: { isGhost: true } })
  360. .apply(StateTransforms.Model.TrajectoryFromMmCif, undefined, { state: { isGhost: true } })
  361. .apply(StateTransforms.Model.ModelFromTrajectory, undefined, { state: { isGhost: true } })
  362. .apply(StateTransforms.Model.StructureFromModel)
  363. .commit()
  364. }
  365. else {
  366. membrane = await state.build().toRoot()
  367. .apply(StateTransforms.Data.ReadFile, { file, isBinary: true, label: file.name }, { state: { isGhost: true } })
  368. .apply(StateTransforms.Data.ParseCif, undefined, { state: { isGhost: true } })
  369. .apply(StateTransforms.Model.TrajectoryFromMmCif, undefined, { state: { isGhost: true } })
  370. .apply(StateTransforms.Model.ModelFromTrajectory, undefined, { state: { isGhost: true } })
  371. .apply(StateTransforms.Model.StructureFromModel)
  372. .commit()
  373. }
  374. const membraneParams = {
  375. representation: params.preset.representation,
  376. }
  377. await CellpackMembranePreset.apply(membrane, membraneParams, plugin)
  378. }
  379. async function loadHivMembrane(plugin: PluginContext, runtime: RuntimeContext, state: State, params: LoadCellPackModelParams) {
  380. const url = `${params.baseUrl}/membranes/hiv_lipids.bcif`
  381. const membrane = await state.build().toRoot()
  382. .apply(StateTransforms.Data.Download, { label: 'hiv_lipids', url, isBinary: true }, { state: { isGhost: true } })
  383. .apply(StateTransforms.Data.ParseCif, undefined, { state: { isGhost: true } })
  384. .apply(StateTransforms.Model.TrajectoryFromMmCif, undefined, { state: { isGhost: true } })
  385. .apply(StateTransforms.Model.ModelFromTrajectory, undefined, { state: { isGhost: true } })
  386. .apply(StateTransforms.Model.StructureFromModel)
  387. .commit()
  388. const membraneParams = {
  389. representation: params.preset.representation,
  390. }
  391. await CellpackMembranePreset.apply(membrane, membraneParams, plugin)
  392. }
  393. async function loadPackings(plugin: PluginContext, runtime: RuntimeContext, state: State, params: LoadCellPackModelParams) {
  394. let cellPackJson: StateBuilder.To<PSO.Format.Json, StateTransformer<PSO.Data.String, PSO.Format.Json>>
  395. if (params.source.name === 'id') {
  396. const url = getCellPackModelUrl(params.source.params, params.baseUrl)
  397. cellPackJson = state.build().toRoot()
  398. .apply(StateTransforms.Data.Download, { url, isBinary: false, label: params.source.params }, { state: { isGhost: true } })
  399. } else {
  400. const file = params.source.params
  401. if (file === null) {
  402. plugin.log.error('No file selected')
  403. return
  404. }
  405. cellPackJson = state.build().toRoot()
  406. .apply(StateTransforms.Data.ReadFile, { file, isBinary: false, label: file.name }, { state: { isGhost: true } })
  407. }
  408. const cellPackBuilder = cellPackJson
  409. .apply(StateTransforms.Data.ParseJson, undefined, { state: { isGhost: true } })
  410. .apply(ParseCellPack)
  411. const cellPackObject = await state.updateTree(cellPackBuilder).runInContext(runtime)
  412. const { packings } = cellPackObject.obj!.data
  413. await handleHivRna({ runtime, fetch: plugin.fetch }, packings, params.baseUrl)
  414. for (let i = 0, il = packings.length; i < il; ++i) {
  415. const p = { packing: i, baseUrl: params.baseUrl, ingredientFiles: params.ingredients.files }
  416. const packing = await state.build()
  417. .to(cellPackBuilder.ref)
  418. .apply(StructureFromCellpack, p)
  419. .commit({ revertOnError: true })
  420. const structure = packing.obj?.data
  421. if (structure) {
  422. await CellPackInfoProvider.attach({ fetch: plugin.fetch, runtime }, structure, {
  423. info: { packingsCount: packings.length, packingIndex: i }
  424. })
  425. }
  426. const packingParams = {
  427. traceOnly: params.preset.traceOnly,
  428. representation: params.preset.representation,
  429. }
  430. await CellpackPackingPreset.apply(packing, packingParams, plugin)
  431. if ( packings[i].location === "surface" ){
  432. await loadMembrane(packings[i].name, plugin, runtime, state, params)
  433. }
  434. }
  435. }
  436. const LoadCellPackModelParams = {
  437. source: PD.MappedStatic('id', {
  438. 'id': PD.Select('influenza_model1.json', [
  439. ['blood_hiv_immature_inside.json', 'blood_hiv_immature_inside'],
  440. ['BloodHIV1.0_mixed_fixed_nc1.cpr', 'BloodHIV1.0_mixed_fixed_nc1'],
  441. ['HIV-1_0.1.6-8_mixed_radii_pdb.cpr', 'HIV-1_0.1.6-8_mixed_radii_pdb'],
  442. ['hiv_lipids.bcif', 'hiv_lipids'],
  443. ['influenza_model1.json', 'influenza_model1'],
  444. ['ExosomeModel.json', 'ExosomeModel'],
  445. ['Mycoplasma1.5_mixed_pdb_fixed.cpr', 'Mycoplasma1.5_mixed_pdb_fixed'],
  446. ] as const),
  447. 'file': PD.File({ accept: 'id' }),
  448. }, { options: [['id', 'Id'], ['file', 'File']] }),
  449. baseUrl: PD.Text(DefaultCellPackBaseUrl),
  450. ingredients : PD.Group({
  451. files: PD.FileList({ accept: '.cif,.pdb' })
  452. }, { isExpanded: true }),
  453. preset: PD.Group({
  454. traceOnly: PD.Boolean(false),
  455. representation: PD.Select('gaussian-surface', PD.arrayToOptions(['spacefill', 'gaussian-surface', 'point', 'ellipsoid']))
  456. }, { isExpanded: true })
  457. }
  458. type LoadCellPackModelParams = PD.Values<typeof LoadCellPackModelParams>
  459. export const LoadCellPackModel = StateAction.build({
  460. display: { name: 'Load CellPack', description: 'Open or download a model' },
  461. params: LoadCellPackModelParams,
  462. from: PSO.Root
  463. })(({ state, params }, ctx: PluginContext) => Task.create('CellPack Loader', async taskCtx => {
  464. if (!ctx.representation.structure.themes.colorThemeRegistry.has(CellPackColorThemeProvider)) {
  465. ctx.representation.structure.themes.colorThemeRegistry.add(CellPackColorThemeProvider)
  466. }
  467. if (params.source.name === 'id' && params.source.params === 'hiv_lipids.bcif') {
  468. await loadHivMembrane(ctx, taskCtx, state, params)
  469. } else {
  470. await loadPackings(ctx, taskCtx, state, params)
  471. }
  472. }));