Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Model, Structure } from "mol-model/structure";
import { CartoonRepresentation } from 'mol-geo/representation/structure/representation/cartoon';
import { BallAndStickRepresentation } from 'mol-geo/representation/structure/representation/ball-and-stick';
import { getStructureFromModel } from "./util";
export interface DefaultView {
readonly model: Model
readonly structure: Structure
readonly cartoon: CartoonRepresentation
readonly ballAndStick: BallAndStickRepresentation
setAssembly(assembly: string): void
}
export async function DefaultView(model: Model, assembly: string): Promise<DefaultView> {
const cartoon = CartoonRepresentation()
const ballAndStick = BallAndStickRepresentation()
let structure: Structure
async function setAssembly(assembly: string) {
structure = await getStructureFromModel(model, assembly)
await createRepr()
}
async function createRepr() {
await cartoon.create(structure, {
colorTheme: { name: 'chain-id' },
sizeTheme: { name: 'uniform', value: 0.2 },
useFog: false // TODO fog not working properly
}).run()
await ballAndStick.create(structure, {
colorTheme: { name: 'element-symbol' },
sizeTheme: { name: 'uniform', value: 0.1 },
useFog: false // TODO fog not working properly
}).run()
}
await setAssembly(assembly)
return {
model,
get structure() { return structure },
cartoon,
ballAndStick,
setAssembly
}
}
// // create new structure via query
// const q1 = Q.generators.atoms({
// residueTest: qtx => SP.residue.label_seq_id(qtx.element) < 7
// });
// const newStructure = StructureSelection.unionStructure(await StructureQuery.run(q1, structure));
// // ball+stick for new structure
// const newBallStickRepr = BallAndStickRepresentation()
// await newBallStickRepr.create(newStructure, {
// colorTheme: { name: 'element-symbol' },
// sizeTheme: { name: 'uniform', value: 0.1 },
// useFog: false // TODO fog not working properly
// }).run()
// viewer.add(newBallStickRepr)
// // create a mesh
// const meshBuilder = MeshBuilder.create(256, 128)
// const colors: Color[] = []
// const labels: string[] = []
// // red sphere
// meshBuilder.setGroup(0)
// colors[0] = Color(0xFF2233)
// labels[0] = 'red sphere'
// addSphere(meshBuilder, Vec3.create(0, 0, 0), 4, 2)
// // green cube
// meshBuilder.setGroup(1)
// colors[1] = Color(0x2233FF)
// labels[1] = 'blue cube'
// const t = Mat4.identity()
// Mat4.fromTranslation(t, Vec3.create(10, 0, 0))
// Mat4.scale(t, t, Vec3.create(3, 3, 3))
// meshBuilder.add(t, Box())
// const mesh = meshBuilder.getMesh()
// const mesh = getObjFromUrl('mesh.obj')
// // create shape from mesh
// const shape = Shape.create('myShape', mesh, colors, labels)
// // add representation from shape
// const customRepr = ShapeRepresentation()
// await customRepr.create(shape, {
// colorTheme: { name: 'shape-group' },
// // colorTheme: { name: 'uniform', value: Color(0xFFCC22) },
// useFog: false // TODO fog not working properly
// }).run()
// viewer.add(customRepr)