model.ts 22 KB

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