|
@@ -10,15 +10,15 @@ import { RenderObject, createMeshRenderObject, MeshRenderObject } from 'mol-gl/s
|
|
|
// import { createColorTexture } from 'mol-gl/util';
|
|
|
import { Vec3, Mat4 } from 'mol-math/linear-algebra'
|
|
|
import { OrderedSet } from 'mol-data/int'
|
|
|
-import { Unit, ElementGroup } from 'mol-model/structure';
|
|
|
+import { Unit, ElementGroup, Element, Queries } from 'mol-model/structure';
|
|
|
import { RepresentationProps, UnitsRepresentation } from './index';
|
|
|
import { Task } from 'mol-task'
|
|
|
import { MeshBuilder } from '../../shape/mesh-builder';
|
|
|
-import { VdwRadius } from 'mol-model/structure/model/properties/atomic';
|
|
|
import { createTransforms, createColors } from './utils';
|
|
|
import { ColorTheme } from '../../theme';
|
|
|
import VertexMap from '../../shape/vertex-map';
|
|
|
import CoarseGrained from 'mol-model/structure/model/properties/coarse-grained';
|
|
|
+import { icosahedronVertexCount } from '../../primitive/icosahedron';
|
|
|
|
|
|
export const DefaultSpacefillProps = {
|
|
|
detail: 0,
|
|
@@ -26,72 +26,43 @@ export const DefaultSpacefillProps = {
|
|
|
}
|
|
|
export type SpacefillProps = Partial<typeof DefaultSpacefillProps>
|
|
|
|
|
|
-function buildAtomSpheres(meshBuilder: MeshBuilder, unit: Unit, elementGroup: ElementGroup, detail: number) {
|
|
|
- return Task.create('Atom spheres', async ctx => {
|
|
|
- if (!Unit.isAtomic(unit)) return
|
|
|
-
|
|
|
- const v = Vec3.zero()
|
|
|
- const m = Mat4.identity()
|
|
|
-
|
|
|
- const { x, y, z } = unit.model.atomSiteConformation
|
|
|
- const { type_symbol } = unit.model.hierarchy.atoms
|
|
|
+function createSpacefillMesh(unit: Unit, elementGroup: ElementGroup, detail: number) {
|
|
|
+ return Task.create('Sphere mesh', async ctx => {
|
|
|
const elementCount = OrderedSet.size(elementGroup.elements)
|
|
|
- for (let i = 0; i < elementCount; i++) {
|
|
|
- const e = OrderedSet.getAt(elementGroup.elements, i)
|
|
|
- v[0] = x[e]
|
|
|
- v[1] = y[e]
|
|
|
- v[2] = z[e]
|
|
|
- Mat4.setTranslation(m, v)
|
|
|
+ const vertexCount = elementCount * icosahedronVertexCount(detail)
|
|
|
+ const meshBuilder = MeshBuilder.create(vertexCount)
|
|
|
|
|
|
- meshBuilder.setId(i)
|
|
|
- meshBuilder.addIcosahedron(m, { radius: VdwRadius(type_symbol.value(e)), detail })
|
|
|
-
|
|
|
- if (i % 10000 === 0 && ctx.shouldUpdate) {
|
|
|
- await ctx.update({ message: 'Atom spheres', current: i, max: elementCount });
|
|
|
- }
|
|
|
+ let radius: Element.Property<number>
|
|
|
+ if (Unit.isAtomic(unit)) {
|
|
|
+ radius = Queries.props.atom.vdw_radius
|
|
|
+ } else if (Unit.isCoarse(unit) && unit.elementType === CoarseGrained.ElementType.Sphere) {
|
|
|
+ radius = Queries.props.coarse_grained.sphere_radius
|
|
|
+ } else {
|
|
|
+ console.warn('Unsupported unit type')
|
|
|
+ return meshBuilder.getMesh()
|
|
|
}
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-function buildCoarseSpheres(meshBuilder: MeshBuilder, unit: Unit, elementGroup: ElementGroup, detail: number) {
|
|
|
- return Task.create('Coarse spheres', async ctx => {
|
|
|
- if (!Unit.isCoarse(unit) || unit.elementType !== CoarseGrained.ElementType.Sphere) return
|
|
|
|
|
|
const v = Vec3.zero()
|
|
|
const m = Mat4.identity()
|
|
|
|
|
|
- const { x, y, z, radius } = unit.model.coarseGrained.spheres
|
|
|
- const elementCount = OrderedSet.size(elementGroup.elements)
|
|
|
- console.log('building coarse spheres', elementCount)
|
|
|
+ const { x, y, z } = unit
|
|
|
+ const l = Element.Location()
|
|
|
+ l.unit = unit
|
|
|
+
|
|
|
for (let i = 0; i < elementCount; i++) {
|
|
|
- const e = OrderedSet.getAt(elementGroup.elements, i)
|
|
|
- v[0] = x[e]
|
|
|
- v[1] = y[e]
|
|
|
- v[2] = z[e]
|
|
|
+ l.element = ElementGroup.getAt(elementGroup, i)
|
|
|
+ v[0] = x(l.element)
|
|
|
+ v[1] = y(l.element)
|
|
|
+ v[2] = z(l.element)
|
|
|
Mat4.setTranslation(m, v)
|
|
|
|
|
|
meshBuilder.setId(i)
|
|
|
- meshBuilder.addIcosahedron(m, { radius: radius.value(e), detail })
|
|
|
+ meshBuilder.addIcosahedron(m, { radius: radius(l), detail })
|
|
|
|
|
|
if (i % 10000 === 0 && ctx.shouldUpdate) {
|
|
|
- await ctx.update({ message: 'Coarse spheres', current: i, max: elementCount });
|
|
|
+ await ctx.update({ message: 'Sphere mesh', current: i, max: elementCount });
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-function createSpacefillMesh(unit: Unit, elementGroup: ElementGroup, detail: number) {
|
|
|
- return Task.create('Spacefill', async ctx => {
|
|
|
- const meshBuilder = MeshBuilder.create()
|
|
|
-
|
|
|
- if (Unit.isAtomic(unit)) {
|
|
|
- await ctx.runChild(buildAtomSpheres(meshBuilder, unit, elementGroup, detail))
|
|
|
- }
|
|
|
-
|
|
|
- if (Unit.isCoarse(unit) && unit.elementType === CoarseGrained.ElementType.Sphere) {
|
|
|
- console.log('building coarse spheres')
|
|
|
- await ctx.runChild(buildCoarseSpheres(meshBuilder, unit, elementGroup, detail))
|
|
|
- }
|
|
|
|
|
|
return meshBuilder.getMesh()
|
|
|
})
|