Skip to content

Commit

Permalink
Make atom visibility a separate option, and don't hyde atoms when sho…
Browse files Browse the repository at this point in the history
…wing shapes
  • Loading branch information
ceriottm authored and Luthaf committed Aug 29, 2023
1 parent fb96b04 commit da0cbc9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/structure/options.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<div class="modal-body">
<h5 class="chsp-settings-section-title">Representation</h5>
<div class="chsp-settings-representation">
<div class="form-check form-switch">
<input class="form-check-input" id="atoms" type="checkbox" />
<label class="form-check-label" for="atoms" title="show atoms as spheres">atoms</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" id="bonds" type="checkbox" />
<label class="form-check-label" for="bonds" title="show bonds between atoms">bonds</label>
Expand Down
4 changes: 4 additions & 0 deletions src/structure/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import HTML_OPTIONS from './options.html.in';
export class StructureOptions extends OptionsGroup {
/// should we show bonds
public bonds: HTMLOption<'boolean'>;
/// should we show atoms
public atoms: HTMLOption<'boolean'>;
/// should we use space filling representation
public spaceFilling: HTMLOption<'boolean'>;
/// should we show atoms labels
Expand Down Expand Up @@ -61,6 +63,7 @@ export class StructureOptions extends OptionsGroup {
super();

this.bonds = new HTMLOption('boolean', true);
this.atoms = new HTMLOption('boolean', true);
this.spaceFilling = new HTMLOption('boolean', false);
this.atomLabels = new HTMLOption('boolean', false);
this.shape = new HTMLOption('string', '');
Expand Down Expand Up @@ -229,6 +232,7 @@ export class StructureOptions extends OptionsGroup {

this.spaceFilling.bind(this.getModalElement('space-filling'), 'checked');
this.bonds.bind(this.getModalElement('bonds'), 'checked');
this.atoms.bind(this.getModalElement('atoms'), 'checked');

this.rotation.bind(this.getModalElement('rotation'), 'checked');
this.unitCell.bind(this.getModalElement('unit-cell'), 'checked');
Expand Down
3 changes: 2 additions & 1 deletion src/structure/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ export class MoleculeViewer {

this._options.spaceFilling.onchange.push(restyleAndRender);
this._options.bonds.onchange.push(restyleAndRender);
this._options.atoms.onchange.push(restyleAndRender);

this._options.atomLabels.onchange.push((showLabels) => {
if (this._current === undefined) {
Expand Down Expand Up @@ -975,7 +976,7 @@ export class MoleculeViewer {
*/
private _mainStyle(): Partial<$3Dmol.AtomStyleSpec> {
const style: Partial<$3Dmol.AtomStyleSpec> = {};
if (this._options.shape.value === '') {
if (this._options.atoms.value) {
style.sphere = {
scale: this._options.spaceFilling.value ? 1.0 : 0.22,
};
Expand Down

0 comments on commit da0cbc9

Please sign in to comment.