# CrystVis

## lib/visualizer.js~ CrystVis

An object providing a full interface to a renderer for crystallographic models

## Constructor

#### # new CrystVis(element, width, height)

An object providing a full interface to a renderer for crystallographic models

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`element` | string |  | CSS-style identifier for the HTML element to put the renderer in
`width` | int | 0 | Window width
`height` | int | 0 | Window height. If both this and width are set to 0, the window fits its context and automatically resizes with it

Source:
  - visualizer.js, line 36

### Members

#### # displayed :ModelView

Displayed atoms

Type:

- ModelView

Source:
  - visualizer.js, line 117

#### # highlightSelected :bool

Whether the selected atoms should be highlighted with auras

Type:

- bool

Source:
  - visualizer.js, line 150

#### # (readonly) model :Model

Currently loaded model

Type:

- Model

Source:
  - visualizer.js, line 100

#### # (readonly) modelList :Array

List of loaded models

Type:

- Array

Source:
  - visualizer.js, line 91

#### # (readonly) modelName :String

Name of the currently loaded model

Type:

- String

Source:
  - visualizer.js, line 109

#### # selected :ModelView

Selected atoms

Type:

- ModelView

Source:
  - visualizer.js, line 134

### Methods

#### # addPrimitive(p)

Add a primitive shape to the drawing

Parameters:

Name | Type | Description
--- | --- | ---
`p` | THREE.Object3D | Primitive to add

Source:
  - visualizer.js, line 428

#### # deleteModel(name)

Erase a model from the recorded ones

Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | Name of the model to delete

Source:
  - visualizer.js, line 410

#### # displayModel(name)

Render a model

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`name` | String | null | Name of the model to display. If empty, just clear the renderer window.

Source:
  - visualizer.js, line 366

#### # getScreenshotData() → {String}

Recover a data URL of a PNG screenshot of the current scene

Source:
  - visualizer.js, line 446

Returns:

A data URL of the PNG screenshot

Type
  String

#### # loadModels(contents, format, prefix, parameters) → {Object}

Load one or more atomic models from a file's contents

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`contents` | String |  | The contents of the structure file
`format` | String | cif | The file's format (cif, xyz, etc.). Default is cif.
`prefix` | String | null | Prefix to use when naming the models. Default is empty.
`parameters` | Object |  | Loading parameters: `supercell`: supercell size (only used if the structure is periodic) `molecularCrystal`: if true, try to make the model load completing molecules across periodic boundaries `useNMRActiveIsotopes`: if true, all isotopes are set by default to the most common one with non-zero spin `vdwScaling`: scale van der Waals radii by a constant factor `vdwElementScaling`: table of per-element factors to scale VdW radii by

Source:
  - visualizer.js, line 291

Returns:

Names of the models we tried to load, and values of true/false for successful loading or not

Type
  Object

#### # onAtomBox(callback)

Set a callback function for an event where a user drags a box around multiple atoms. The function should take as arguments a ModelView including the atoms in the box:

function callback(view) { ... }

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`callback` | function | null | Callback function for the event. Passing "null" restores default behaviour

Source:
  - visualizer.js, line 215

#### # onAtomClick(callback, modifiers)

Set a callback function for an event where a user clicks on an atom. The function should take as arguments the atom image for the clicked atom and the event object:

function callback(atom, event) { ... }

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`callback` | function | null | Callback function for the event. Passing "null" restores default behaviour
`modifiers` | int |  | Click event. Use the following flags to define it: CrystVis.LEFT_CLICK CrystVis.RIGHT_CLICK CrystVis.MIDDLE_CLICK CrystVis.CTRL_BUTTON CrystVis.ALT_BUTTON CrystVis.SHIFT_BUTTON CrystVis.CMD_BUTTON For example, CrystVis.LEFT_CLICK + CrystVis.SHIFT_BUTTON defines the event for a click while the Shift key is pressed.

Source:
  - visualizer.js, line 185

#### # reloadModel(name, parameters)

Reload a model, possibly with new parameters

Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | Name of the model to reload.
`parameters` | Object | Loading parameters as in .loadModels()

Source:
  - visualizer.js, line 338

#### # removePrimitive(p)

Remove a primitive shape from the drawing

Parameters:

Name | Type | Description
--- | --- | ---
`p` | THREE.Object3D | Primitive to remove

Source:
  - visualizer.js, line 437