diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e022d7ac4ace871e72769c72f3fc3c297ad04d3..ef6b0bd6c30ca87c543fbc09f248f3361ff42be3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note that since we don't clearly distinguish between a public and private interf - Fix `QualityAssessment` assignment bug for structures with different auth vs label sequence numbering - Refresh `ApplyActionControl`'s param definition when toggling expanded state - Fix `struct_conn` bond assignment for ions +- Ability to show only polar hydrogens ## [v3.26.0] - 2022-12-04 diff --git a/src/extensions/cellpack/model.ts b/src/extensions/cellpack/model.ts index 91ea9c33315343732112fe22b80829545b5edc90..6293d8a729b7eea644f1cda9ca58f684e9c9ff34 100644 --- a/src/extensions/cellpack/model.ts +++ b/src/extensions/cellpack/model.ts @@ -585,7 +585,7 @@ export const LoadCellPackModel = StateAction.build({ ... ctx.managers.structure.component.state.options, visualQuality: 'custom', ignoreLight: true, - showHydrogens: false, + hydrogens: 'hide-all', }); ctx.canvas3d?.setProps({ multiSample: { mode: 'off' }, diff --git a/src/mol-plugin-state/builder/structure/representation-preset.ts b/src/mol-plugin-state/builder/structure/representation-preset.ts index 25f2d1f907f1772b52a9da01ff27d0d91df9bfad..2f5d6d410c7a7caadaee2844e4c6ae52404f61e9 100644 --- a/src/mol-plugin-state/builder/structure/representation-preset.ts +++ b/src/mol-plugin-state/builder/structure/representation-preset.ts @@ -37,6 +37,7 @@ export namespace StructureRepresentationPresetProvider { export const CommonParams = { ignoreHydrogens: PD.Optional(PD.Boolean(false)), + onlyPolarHydrogens: PD.Optional(PD.Boolean(false)), ignoreLight: PD.Optional(PD.Boolean(false)), quality: PD.Optional(PD.Select<VisualQuality>('auto', VisualQualityOptions)), theme: PD.Optional(PD.Group({ @@ -70,11 +71,13 @@ export namespace StructureRepresentationPresetProvider { const builder = plugin.builders.structure.representation; const typeParams = { quality: plugin.managers.structure.component.state.options.visualQuality, - ignoreHydrogens: !plugin.managers.structure.component.state.options.showHydrogens, + ignoreHydrogens: plugin.managers.structure.component.state.options.hydrogens === 'hide-all', + onlyPolarHydrogens: plugin.managers.structure.component.state.options.hydrogens === 'only-polar', ignoreLight: plugin.managers.structure.component.state.options.ignoreLight, }; if (params.quality && params.quality !== 'auto') typeParams.quality = params.quality; if (params.ignoreHydrogens !== void 0) typeParams.ignoreHydrogens = !!params.ignoreHydrogens; + if (params.onlyPolarHydrogens !== void 0) typeParams.onlyPolarHydrogens = !!params.onlyPolarHydrogens; if (params.ignoreLight !== void 0) typeParams.ignoreLight = !!params.ignoreLight; const color: ColorTheme.BuiltIn | undefined = params.theme?.globalName ? params.theme?.globalName : void 0; const ballAndStickColor: ColorTheme.BuiltInParams<'element-symbol'> = params.theme?.carbonColor !== undefined diff --git a/src/mol-plugin-state/manager/structure/component.ts b/src/mol-plugin-state/manager/structure/component.ts index 229ece724ee5a43a85473309cbba47870268bfb3..d8c3f4d4873f0d9f0463067292bf1084e00620b7 100644 --- a/src/mol-plugin-state/manager/structure/component.ts +++ b/src/mol-plugin-state/manager/structure/component.ts @@ -70,7 +70,8 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone return this.plugin.dataTransaction(async () => { await update.commit(); await this.plugin.state.updateBehavior(StructureFocusRepresentation, p => { - p.ignoreHydrogens = !options.showHydrogens; + p.ignoreHydrogens = options.hydrogens === 'hide-all'; + p.onlyPolarHydrogens = options.hydrogens === 'only-polar'; p.ignoreLight = options.ignoreLight; p.material = options.materialStyle; p.clip = options.clipObjects; @@ -80,15 +81,17 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone } private updateReprParams(update: StateBuilder.Root, component: StructureComponentRef) { - const { showHydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; - const ignoreHydrogens = !showHydrogens; + const { hydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; + const ignoreHydrogens = hydrogens === 'hide-all'; + const onlyPolarHydrogens = hydrogens === 'only-polar'; for (const r of component.representations) { if (r.cell.transform.transformer !== StructureRepresentation3D) continue; const params = r.cell.transform.params as StateTransformer.Params<StructureRepresentation3D>; - if (!!params.type.params.ignoreHydrogens !== ignoreHydrogens || params.type.params.quality !== quality || params.type.params.ignoreLight !== ignoreLight || !shallowEqual(params.type.params.material, material) || !PD.areEqual(Clip.Params, params.type.params.clip, clip)) { + if (!!params.type.params.ignoreHydrogens !== ignoreHydrogens || !!params.type.params.onlyPolarHydrogens !== onlyPolarHydrogens || params.type.params.quality !== quality || params.type.params.ignoreLight !== ignoreLight || !shallowEqual(params.type.params.material, material) || !PD.areEqual(Clip.Params, params.type.params.clip, clip)) { update.to(r.cell).update(old => { old.type.params.ignoreHydrogens = ignoreHydrogens; + old.type.params.onlyPolarHydrogens = onlyPolarHydrogens; old.type.params.quality = quality; old.type.params.ignoreLight = ignoreLight; old.type.params.material = material; @@ -311,9 +314,10 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone addRepresentation(components: ReadonlyArray<StructureComponentRef>, type: string) { if (components.length === 0) return; - const { showHydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; - const ignoreHydrogens = !showHydrogens; - const typeParams = { ignoreHydrogens, quality, ignoreLight, material, clip }; + const { hydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; + const ignoreHydrogens = hydrogens === 'hide-all'; + const onlyPolarHydrogens = hydrogens === 'only-polar'; + const typeParams = { ignoreHydrogens, onlyPolarHydrogens, quality, ignoreLight, material, clip }; return this.plugin.dataTransaction(async () => { for (const component of components) { @@ -348,9 +352,10 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone const xs = structures || this.currentStructures; if (xs.length === 0) return; - const { showHydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; - const ignoreHydrogens = !showHydrogens; - const typeParams = { ignoreHydrogens, quality, ignoreLight, material, clip }; + const { hydrogens, visualQuality: quality, ignoreLight, materialStyle: material, clipObjects: clip } = this.state.options; + const ignoreHydrogens = hydrogens === 'hide-all'; + const onlyPolarHydrogens = hydrogens === 'only-polar'; + const typeParams = { ignoreHydrogens, onlyPolarHydrogens, quality, ignoreLight, material, clip }; const componentKey = UUID.create22(); for (const s of xs) { @@ -458,9 +463,13 @@ class StructureComponentManager extends StatefulPluginComponent<StructureCompone namespace StructureComponentManager { export const OptionsParams = { - showHydrogens: PD.Boolean(true, { description: 'Toggle display of hydrogen atoms in representations' }), + hydrogens: PD.Select( + 'all', + [['all', 'Show All'], ['hide-all', 'Hide All'], ['only-polar', 'Only Polar']] as const, + { description: 'Determine display of hydrogen atoms in representations' } + ), visualQuality: PD.Select('auto', VisualQualityOptions, { description: 'Control the visual/rendering quality of representations' }), - ignoreLight: PD.Boolean(false, { description: 'Ignore light for stylized rendering of representtions' }), + ignoreLight: PD.Boolean(false, { description: 'Ignore light for stylized rendering of representations' }), materialStyle: Material.getParam(), clipObjects: PD.Group(Clip.Params), interactions: PD.Group(InteractionsProvider.defaultParams, { label: 'Non-covalent Interactions' }), diff --git a/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts b/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts index a53dab23f2b1f6e707186d64713d8e744d01941f..e548d8e8b0117d630ce2bdb6b85d4440e73618e0 100644 --- a/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts +++ b/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts @@ -52,6 +52,7 @@ const StructureFocusRepresentationParams = (plugin: PluginContext) => { components: PD.MultiSelect(FocusComponents, PD.arrayToOptions(FocusComponents)), excludeTargetFromSurroundings: PD.Boolean(false, { label: 'Exclude Target', description: 'Exclude the focus "target" from the surroudings component.' }), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), ignoreLight: PD.Boolean(false), material: Material.getParam(), clip: PD.Group(Clip.Params), @@ -80,7 +81,7 @@ class StructureFocusRepresentationBehavior extends PluginBehavior.WithSubscriber ...reprParams, type: { name: reprParams.type.name, - params: { ...reprParams.type.params, ignoreHydrogens: this.params.ignoreHydrogens, ignoreLight: this.params.ignoreLight, material: this.params.material, clip: this.params.clip } + params: { ...reprParams.type.params, ignoreHydrogens: this.params.ignoreHydrogens, onlyPolarHydrogens: this.params.onlyPolarHydrogens, ignoreLight: this.params.ignoreLight, material: this.params.material, clip: this.params.clip } } }; } diff --git a/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts b/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts index d097587e911fdc6910d6b8bb8e574433a79cce2c..0d9476ce3d49cffac7f03538de7c9e25939c18ca 100644 --- a/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts +++ b/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts @@ -222,6 +222,7 @@ export function InterUnitBondCylinderImpostorVisual(materialId: number): Complex newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.linkCap !== currentProps.linkCap || newProps.aromaticScale !== currentProps.aromaticScale || newProps.aromaticSpacing !== currentProps.aromaticSpacing || @@ -264,6 +265,7 @@ export function InterUnitBondCylinderMeshVisual(materialId: number): ComplexVisu newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.linkCap !== currentProps.linkCap || newProps.aromaticScale !== currentProps.aromaticScale || newProps.aromaticSpacing !== currentProps.aromaticSpacing || diff --git a/src/mol-repr/structure/visual/bond-inter-unit-line.ts b/src/mol-repr/structure/visual/bond-inter-unit-line.ts index f7cda2e4aac21e0ff604a2ac7ed311a98b85175c..ab6c1436b2bf8e72ea202baf37d17af9fbb73de9 100644 --- a/src/mol-repr/structure/visual/bond-inter-unit-line.ts +++ b/src/mol-repr/structure/visual/bond-inter-unit-line.ts @@ -138,6 +138,7 @@ export function InterUnitBondLineVisual(materialId: number): ComplexVisual<Inter newProps.aromaticDashCount !== currentProps.aromaticDashCount || newProps.dashCount !== currentProps.dashCount || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || !arrayEqual(newProps.includeTypes, currentProps.includeTypes) || !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) || newProps.multipleBonds !== currentProps.multipleBonds diff --git a/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts b/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts index ec837f48eebd89e02b9fbcf1af3095eb6785560e..5e2e95dadf39197bfeb4ec4078b4712e43187573 100644 --- a/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts +++ b/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts @@ -239,6 +239,7 @@ export function IntraUnitBondCylinderImpostorVisual(materialId: number): UnitsVi newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.linkCap !== currentProps.linkCap || newProps.aromaticScale !== currentProps.aromaticScale || newProps.aromaticSpacing !== currentProps.aromaticSpacing || @@ -286,6 +287,7 @@ export function IntraUnitBondCylinderMeshVisual(materialId: number): UnitsVisual newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.linkCap !== currentProps.linkCap || newProps.aromaticScale !== currentProps.aromaticScale || newProps.aromaticSpacing !== currentProps.aromaticSpacing || diff --git a/src/mol-repr/structure/visual/bond-intra-unit-line.ts b/src/mol-repr/structure/visual/bond-intra-unit-line.ts index 68d1ca4f957cdaa27a37a280f6c41cc7823f9eeb..640d93cda7384a7e2ba470aacfb29c2a113b4141 100644 --- a/src/mol-repr/structure/visual/bond-intra-unit-line.ts +++ b/src/mol-repr/structure/visual/bond-intra-unit-line.ts @@ -164,6 +164,7 @@ export function IntraUnitBondLineVisual(materialId: number): UnitsVisual<IntraUn newProps.aromaticDashCount !== currentProps.aromaticDashCount || newProps.dashCount !== currentProps.dashCount || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || !arrayEqual(newProps.includeTypes, currentProps.includeTypes) || !arrayEqual(newProps.excludeTypes, currentProps.excludeTypes) || newProps.aromaticBonds !== currentProps.aromaticBonds || diff --git a/src/mol-repr/structure/visual/element-cross.ts b/src/mol-repr/structure/visual/element-cross.ts index 557a970feedadcd0090fc661e273dc0d7647df62..d69d80ba3a583ffa01dd3c7106ca245b4ce91f5c 100644 --- a/src/mol-repr/structure/visual/element-cross.ts +++ b/src/mol-repr/structure/visual/element-cross.ts @@ -27,6 +27,7 @@ export const ElementCrossParams = { ...UnitsLinesParams, lineSizeAttenuation: PD.Boolean(false), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), traceOnly: PD.Boolean(false), crosses: PD.Select('lone', PD.arrayToOptions(['lone', 'all'] as const)), crossSize: PD.Numeric(0.35, { min: 0, max: 2, step: 0.01 }), @@ -85,6 +86,7 @@ export function ElementCrossVisual(materialId: number): UnitsVisual<ElementCross setUpdateState: (state: VisualUpdateState, newProps: PD.Values<ElementCrossParams>, currentProps: PD.Values<ElementCrossParams>) => { state.createGeometry = ( newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.traceOnly !== currentProps.traceOnly || newProps.crosses !== currentProps.crosses || newProps.crossSize !== currentProps.crossSize diff --git a/src/mol-repr/structure/visual/element-point.ts b/src/mol-repr/structure/visual/element-point.ts index 05dd4740d4e5b9f921511604fa02363f3b0c7454..a50e5fc9cdd5e39f01bccd79b29e7b84dccac7c2 100644 --- a/src/mol-repr/structure/visual/element-point.ts +++ b/src/mol-repr/structure/visual/element-point.ts @@ -23,6 +23,7 @@ export const ElementPointParams = { ...UnitsPointsParams, pointSizeAttenuation: PD.Boolean(false), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), traceOnly: PD.Boolean(false), }; export type ElementPointParams = typeof ElementPointParams @@ -89,6 +90,7 @@ export function ElementPointVisual(materialId: number): UnitsVisual<ElementPoint setUpdateState: (state: VisualUpdateState, newProps: PD.Values<ElementPointParams>, currentProps: PD.Values<ElementPointParams>) => { state.createGeometry = ( newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.traceOnly !== currentProps.traceOnly ); } diff --git a/src/mol-repr/structure/visual/element-sphere.ts b/src/mol-repr/structure/visual/element-sphere.ts index e7fc70aa05915aa37240e705ef41c1f265c08e45..909934efd8b6e630921ca1e2126b12f7c27e60d4 100644 --- a/src/mol-repr/structure/visual/element-sphere.ts +++ b/src/mol-repr/structure/visual/element-sphere.ts @@ -20,6 +20,7 @@ export const ElementSphereParams = { sizeFactor: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }), detail: PD.Numeric(0, { min: 0, max: 3, step: 1 }, BaseGeometry.CustomQualityParamInfo), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), traceOnly: PD.Boolean(false), tryUseImpostor: PD.Boolean(true), }; @@ -41,6 +42,7 @@ export function ElementSphereImpostorVisual(materialId: number): UnitsVisual<Ele setUpdateState: (state: VisualUpdateState, newProps: PD.Values<ElementSphereParams>, currentProps: PD.Values<ElementSphereParams>) => { state.createGeometry = ( newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.traceOnly !== currentProps.traceOnly ); }, @@ -62,6 +64,7 @@ export function ElementSphereMeshVisual(materialId: number): UnitsVisual<Element newProps.sizeFactor !== currentProps.sizeFactor || newProps.detail !== currentProps.detail || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || + newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens || newProps.traceOnly !== currentProps.traceOnly ); }, diff --git a/src/mol-repr/structure/visual/gaussian-density-volume.ts b/src/mol-repr/structure/visual/gaussian-density-volume.ts index 21deb9c37678c56fec7d16ba6d2996180a3d2323..e347f81433bc9acec7f99bc23a1fb2f9a0d7bd93 100644 --- a/src/mol-repr/structure/visual/gaussian-density-volume.ts +++ b/src/mol-repr/structure/visual/gaussian-density-volume.ts @@ -43,6 +43,7 @@ export const GaussianDensityVolumeParams = { ...ComplexDirectVolumeParams, ...GaussianDensityParams, ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }), }; export type GaussianDensityVolumeParams = typeof GaussianDensityVolumeParams @@ -59,6 +60,7 @@ export function GaussianDensityVolumeVisual(materialId: number): ComplexVisual<G if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; }, @@ -99,6 +101,7 @@ export const UnitsGaussianDensityVolumeParams = { ...UnitsDirectVolumeParams, ...GaussianDensityParams, ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }), }; export type UnitsGaussianDensityVolumeParams = typeof UnitsGaussianDensityVolumeParams @@ -115,6 +118,7 @@ export function UnitsGaussianDensityVolumeVisual(materialId: number): UnitsVisua if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; }, diff --git a/src/mol-repr/structure/visual/gaussian-surface-mesh.ts b/src/mol-repr/structure/visual/gaussian-surface-mesh.ts index b8223d3a42185024d59922bd4976c790e9be0321..06e2116850896ac4603e87c509e2731448396bd2 100644 --- a/src/mol-repr/structure/visual/gaussian-surface-mesh.ts +++ b/src/mol-repr/structure/visual/gaussian-surface-mesh.ts @@ -34,6 +34,7 @@ const SharedParams = { ...GaussianDensityParams, ...ColorSmoothingParams, ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), tryUseGpu: PD.Boolean(true), includeParent: PD.Boolean(false, { isHidden: true }), }; @@ -127,6 +128,7 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; if (newProps.smoothColors.name !== currentProps.smoothColors.name) { @@ -193,6 +195,7 @@ export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexV if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.smoothColors.name !== currentProps.smoothColors.name) { state.updateColor = true; @@ -264,6 +267,7 @@ export function GaussianSurfaceTextureMeshVisual(materialId: number): UnitsVisua if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; if (newProps.smoothColors.name !== currentProps.smoothColors.name) { @@ -339,6 +343,7 @@ export function StructureGaussianSurfaceTextureMeshVisual(materialId: number): C if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; if (newProps.smoothColors.name !== currentProps.smoothColors.name) { diff --git a/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts b/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts index aa5cddb98437596aeb3d70dab436cf1448524d81..59eb1bc9cd1f924d947c3a88a868597a3ee361fe 100644 --- a/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts +++ b/src/mol-repr/structure/visual/gaussian-surface-wireframe.ts @@ -41,6 +41,7 @@ export const GaussianWireframeParams = { sizeFactor: PD.Numeric(3, { min: 0, max: 10, step: 0.1 }), lineSizeAttenuation: PD.Boolean(false), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }), }; export type GaussianWireframeParams = typeof GaussianWireframeParams @@ -57,6 +58,7 @@ export function GaussianWireframeVisual(materialId: number): UnitsVisual<Gaussia if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; } diff --git a/src/mol-repr/structure/visual/molecular-surface-mesh.ts b/src/mol-repr/structure/visual/molecular-surface-mesh.ts index d30c6d4ee499bb239587182177d6916da47f471f..5e0608039b102033f7f1754abd0a4c4dd1c77590 100644 --- a/src/mol-repr/structure/visual/molecular-surface-mesh.ts +++ b/src/mol-repr/structure/visual/molecular-surface-mesh.ts @@ -83,6 +83,7 @@ export function MolecularSurfaceMeshVisual(materialId: number): UnitsVisual<Mole if (newProps.probeRadius !== currentProps.probeRadius) state.createGeometry = true; if (newProps.probePositions !== currentProps.probePositions) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; @@ -151,6 +152,7 @@ export function StructureMolecularSurfaceMeshVisual(materialId: number): Complex if (newProps.probeRadius !== currentProps.probeRadius) state.createGeometry = true; if (newProps.probePositions !== currentProps.probePositions) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; diff --git a/src/mol-repr/structure/visual/molecular-surface-wireframe.ts b/src/mol-repr/structure/visual/molecular-surface-wireframe.ts index f3a2c07788a8676a98933609e2ae2b0057840d7c..45b93917a3c66a3aeca9a00e968e0d50c06aa97d 100644 --- a/src/mol-repr/structure/visual/molecular-surface-wireframe.ts +++ b/src/mol-repr/structure/visual/molecular-surface-wireframe.ts @@ -57,6 +57,7 @@ export function MolecularSurfaceWireframeVisual(materialId: number): UnitsVisual if (newProps.probeRadius !== currentProps.probeRadius) state.createGeometry = true; if (newProps.probePositions !== currentProps.probePositions) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; + if (newProps.onlyPolarHydrogens !== currentProps.onlyPolarHydrogens) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; } }, materialId); diff --git a/src/mol-repr/structure/visual/util/bond.ts b/src/mol-repr/structure/visual/util/bond.ts index 61086d2585c30e9da0ba80ce8ec7338581bdac45..4fc89d01935a742bceaebb76e6c962ff18681ce2 100644 --- a/src/mol-repr/structure/visual/util/bond.ts +++ b/src/mol-repr/structure/visual/util/bond.ts @@ -2,6 +2,7 @@ * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> + * @author David Sehnal <david.sehnal@gmail.com> */ import { BondType } from '../../../../mol-model/structure/model/types'; @@ -14,11 +15,13 @@ import { PickingId } from '../../../../mol-geo/geometry/picking'; import { EmptyLoci, Loci } from '../../../../mol-model/loci'; import { Interval, OrderedSet, SortedArray } from '../../../../mol-data/int'; import { isH, isHydrogen, StructureGroup } from './common'; +import { hasPolarNeighbour } from '../../../../mol-model-props/computed/chemistry/functional-group'; export const BondParams = { includeTypes: PD.MultiSelect(ObjectKeys(BondType.Names), PD.objectToOptions(BondType.Names)), excludeTypes: PD.MultiSelect([] as BondType.Names[], PD.objectToOptions(BondType.Names)), ignoreHydrogens: PD.Boolean(false), + onlyPolarHydrogens: PD.Boolean(false), aromaticBonds: PD.Boolean(true, { description: 'Display aromatic bonds with dashes' }), multipleBonds: PD.Select('symmetric', PD.arrayToOptions(['off', 'symmetric', 'offset'] as const)), }; @@ -51,7 +54,7 @@ export function makeIntraBondIgnoreTest(structure: Structure, unit: Unit.Atomic, const { a, b, edgeProps } = bonds; const { flags: _flags } = edgeProps; - const { ignoreHydrogens, includeTypes, excludeTypes } = props; + const { ignoreHydrogens, onlyPolarHydrogens, includeTypes, excludeTypes } = props; const include = BondType.fromNames(includeTypes); const exclude = BondType.fromNames(excludeTypes); @@ -61,14 +64,31 @@ export function makeIntraBondIgnoreTest(structure: Structure, unit: Unit.Atomic, const childUnit = child?.unitMap.get(unit.id); if (child && !childUnit) throw new Error('expected childUnit to exist if child exists'); - if (allBondTypes && !ignoreHydrogens && !child) return; + if (allBondTypes && !onlyPolarHydrogens && !ignoreHydrogens && !child) return; return (edgeIndex: number) => { - return ( - (!!childUnit && !SortedArray.has(childUnit.elements, elements[a[edgeIndex]])) || - (ignoreHydrogens && (isH(atomicNumber, elements[a[edgeIndex]]) || isH(atomicNumber, elements[b[edgeIndex]]))) || - (!allBondTypes && ignoreBondType(include, exclude, _flags[edgeIndex])) - ); + const aI = a[edgeIndex]; + const bI = b[edgeIndex]; + + if ((!!childUnit && !SortedArray.has(childUnit.elements, elements[aI]))) { + return true; + } + + if (!allBondTypes && ignoreBondType(include, exclude, _flags[edgeIndex])) { + return true; + } + + if (!ignoreHydrogens && !onlyPolarHydrogens) return false; + if (isH(atomicNumber, elements[aI])) { + if (ignoreHydrogens) return true; + if (onlyPolarHydrogens && !hasPolarNeighbour(structure, unit, aI)) return true; + } + if (isH(atomicNumber, elements[bI])) { + if (ignoreHydrogens) return true; + if (onlyPolarHydrogens && !hasPolarNeighbour(structure, unit, bI)) return true; + } + + return false; }; } @@ -76,7 +96,7 @@ export function makeInterBondIgnoreTest(structure: Structure, props: BondProps): const bonds = structure.interUnitBonds; const { edges } = bonds; - const { ignoreHydrogens, includeTypes, excludeTypes } = props; + const { ignoreHydrogens, onlyPolarHydrogens, includeTypes, excludeTypes } = props; const include = BondType.fromNames(includeTypes); const exclude = BondType.fromNames(excludeTypes); @@ -84,7 +104,7 @@ export function makeInterBondIgnoreTest(structure: Structure, props: BondProps): const { child } = structure; - if (allBondTypes && !ignoreHydrogens && !child) return; + if (allBondTypes && !onlyPolarHydrogens && !ignoreHydrogens && !child) return; return (edgeIndex: number) => { if (child) { @@ -104,6 +124,18 @@ export function makeInterBondIgnoreTest(structure: Structure, props: BondProps): if (isHydrogen(uA, uA.elements[b.indexA]) || isHydrogen(uB, uB.elements[b.indexB])) return true; } + if (onlyPolarHydrogens) { + const b = edges[edgeIndex]; + const uA = structure.unitMap.get(b.unitA); + if (isHydrogen(uA, uA.elements[b.indexA]) && !hasPolarNeighbour(structure, uA as Unit.Atomic, b.indexA)) { + return true; + } + const uB = structure.unitMap.get(b.unitB); + if (isHydrogen(uB, uB.elements[b.indexB]) && !hasPolarNeighbour(structure, uB as Unit.Atomic, b.indexB)) { + return true; + } + } + if (!allBondTypes) { if (ignoreBondType(include, exclude, edges[edgeIndex].props.flag)) return true; } diff --git a/src/mol-repr/structure/visual/util/common.ts b/src/mol-repr/structure/visual/util/common.ts index 50d3f2659866cf41cfea42ed9147cb4a90dcc6b4..e2e9aa0156e51c1a612d79494d4afbfa46565d00 100644 --- a/src/mol-repr/structure/visual/util/common.ts +++ b/src/mol-repr/structure/visual/util/common.ts @@ -2,6 +2,7 @@ * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> + * @author David Sehnal <david.sehnal@gmail.com> */ import { Unit, Structure, ElementIndex, StructureElement, ResidueIndex } from '../../../../mol-model/structure'; @@ -16,6 +17,7 @@ import { AssignableArrayLike } from '../../../../mol-util/type-helpers'; import { getBoundary } from '../../../../mol-math/geometry/boundary'; import { Box3D } from '../../../../mol-math/geometry'; import { SizeTheme } from '../../../../mol-theme/size'; +import { hasPolarNeighbour } from '../../../../mol-model-props/computed/chemistry/functional-group'; /** Return a Loci for the elements of a whole residue the elementIndex belongs to. */ export function getResidueLoci(structure: Structure, unit: Unit.Atomic, elementIndex: ElementIndex): Loci { @@ -139,6 +141,7 @@ export function getConformation(unit: Unit) { export const CommonSurfaceParams = { ignoreHydrogens: PD.Boolean(false, { description: 'Whether or not to include hydrogen atoms in the surface calculation.' }), + onlyPolarHydrogens: PD.Boolean(false, { description: 'Whether or not to include polar hydrogen atoms in the surface calculation.' }), traceOnly: PD.Boolean(false, { description: 'Whether or not to only use trace atoms in the surface calculation.' }), includeParent: PD.Boolean(false, { description: 'Include elements of the parent structure in surface calculation to get a surface patch of the current structure.' }), }; @@ -166,7 +169,7 @@ function filterUnitId(id: AssignableArrayLike<number>, elements: SortedArray, in } export function getUnitConformationAndRadius(structure: Structure, unit: Unit, sizeTheme: SizeTheme<any>, props: CommonSurfaceProps) { - const { ignoreHydrogens, traceOnly, includeParent } = props; + const { ignoreHydrogens, onlyPolarHydrogens, traceOnly, includeParent } = props; const rootUnit = includeParent ? structure.root.unitMap.get(unit.id) : unit; const differentRoot = includeParent && rootUnit !== unit; @@ -179,12 +182,13 @@ export function getUnitConformationAndRadius(structure: Structure, unit: Unit, s let indices: SortedArray<ElementIndex>; let id: AssignableArrayLike<number>; - if (ignoreHydrogens || traceOnly || differentRoot) { + if (ignoreHydrogens || onlyPolarHydrogens || traceOnly || differentRoot) { const _indices: number[] = []; const _id: number[] = []; for (let i = 0, il = elements.length; i < il; ++i) { const eI = elements[i]; if (ignoreHydrogens && isHydrogen(rootUnit, eI)) continue; + if (onlyPolarHydrogens && isHydrogen(rootUnit, eI) && Unit.isAtomic(rootUnit) && !hasPolarNeighbour(structure, rootUnit, SortedArray.indexOf(rootUnit.elements, eI) as StructureElement.UnitIndex)) continue; if (traceOnly && !isTrace(rootUnit, eI)) continue; if (differentRoot && squaredDistance(x[eI], y[eI], z[eI], center) > radiusSq) continue; @@ -215,7 +219,7 @@ export function getUnitConformationAndRadius(structure: Structure, unit: Unit, s } export function getStructureConformationAndRadius(structure: Structure, sizeTheme: SizeTheme<any>, props: CommonSurfaceProps) { - const { ignoreHydrogens, traceOnly, includeParent } = props; + const { ignoreHydrogens, onlyPolarHydrogens, traceOnly, includeParent } = props; const differentRoot = includeParent && !!structure.parent; const l = StructureElement.Location.create(structure.root); @@ -230,7 +234,7 @@ export function getStructureConformationAndRadius(structure: Structure, sizeThem let id: AssignableArrayLike<number>; let indices: OrderedSet<number>; - if (ignoreHydrogens || traceOnly || differentRoot) { + if (ignoreHydrogens || onlyPolarHydrogens || traceOnly || differentRoot) { const { getSerialIndex } = structure.serialMapping; const units = differentRoot ? structure.root.units : structure.units; @@ -249,6 +253,7 @@ export function getStructureConformationAndRadius(structure: Structure, sizeThem for (let j = 0, jl = elements.length; j < jl; ++j) { const eI = elements[j]; if (ignoreHydrogens && isHydrogen(unit, eI)) continue; + if (onlyPolarHydrogens && isHydrogen(unit, eI) && Unit.isAtomic(unit) && !hasPolarNeighbour(structure, unit, SortedArray.indexOf(unit.elements, eI) as StructureElement.UnitIndex)) continue; if (traceOnly && !isTrace(unit, eI)) continue; const _x = x(eI), _y = y(eI), _z = z(eI); diff --git a/src/mol-repr/structure/visual/util/element.ts b/src/mol-repr/structure/visual/util/element.ts index 2c51b20c6eac4deaef9d914ec4761106f875a3a7..a55a776bec0fa596c5cadff9fdd2e30510fe93c8 100644 --- a/src/mol-repr/structure/visual/util/element.ts +++ b/src/mol-repr/structure/visual/util/element.ts @@ -21,12 +21,14 @@ import { Spheres } from '../../../../mol-geo/geometry/spheres/spheres'; import { SpheresBuilder } from '../../../../mol-geo/geometry/spheres/spheres-builder'; import { isTrace, isH, StructureGroup } from './common'; import { Sphere3D } from '../../../../mol-math/geometry'; +import { hasPolarNeighbour } from '../../../../mol-model-props/computed/chemistry/functional-group'; // avoiding namespace lookup improved performance in Chrome (Aug 2020) const v3add = Vec3.add; type ElementProps = { ignoreHydrogens: boolean, + onlyPolarHydrogens: boolean, traceOnly: boolean, } @@ -36,7 +38,7 @@ export type ElementSphereMeshProps = { } & ElementProps export function makeElementIgnoreTest(structure: Structure, unit: Unit, props: ElementProps): undefined | ((i: ElementIndex) => boolean) { - const { ignoreHydrogens, traceOnly } = props; + const { ignoreHydrogens, onlyPolarHydrogens, traceOnly } = props; const { atomicNumber } = unit.model.atomicHierarchy.derived.atom; const isCoarse = Unit.isCoarse(unit); @@ -45,14 +47,26 @@ export function makeElementIgnoreTest(structure: Structure, unit: Unit, props: E const childUnit = child?.unitMap.get(unit.id); if (child && !childUnit) throw new Error('expected childUnit to exist if child exists'); - if (!child && !ignoreHydrogens && !traceOnly) return; + if (!child && !ignoreHydrogens && !traceOnly && !onlyPolarHydrogens) return; return (element: ElementIndex) => { - return ( - (!!childUnit && !SortedArray.has(childUnit.elements, element)) || - (!isCoarse && ignoreHydrogens && isH(atomicNumber, element)) || - (traceOnly && !isTrace(unit, element)) - ); + if (!!childUnit && !SortedArray.has(childUnit.elements, element)) { + return true; + } + + if (traceOnly && !isTrace(unit, element)) { + return true; + } + + if (isCoarse) return false; + + if (!isH(atomicNumber, element)) return false; + if (ignoreHydrogens) return true; + if (onlyPolarHydrogens) { + return !hasPolarNeighbour(structure, unit, SortedArray.indexOf(unit.elements, element) as StructureElement.UnitIndex); + } + + return false; }; }