$3Dmol.download('cid:...', ...) - Download CID Molecule

Q

How to download molecule by CID with the $3Dmol.download() method?

✍: FYIcenter.com

A

The syntax to download molecule by CID with the $3Dmol.download() method is shown below:

$3Dmol.download("cid:{CID}", viewer, options, callback) -> {$3Dmol.GLModel}
  viewer - The $3Dmol.GLViewer instance where the downloaded protein is added
  options - Options applied to the downloaded data 
  callback - Function to call after data is loaded with model as argument

Here is an HTML code example, Download-PDB.html, that uses the download() method to download a protein with a given CID number.

<html><head>
<script src="/3Dmol-min.js"></script>
</head>
<body>
<div id="viewer" style="width: 400px; height: 400px; position: relative;"></div>
<script>
  let config = { backgroundColor: 'grey' };
  let viewer = $3Dmol.createViewer( $('#viewer'), config );
  $3Dmol.download('cid:2719', viewer, {}, function(m) {
    m.setStyle({'stick':{}});
    viewer.render();
  });
</script>
</body></html>

This example HTML code will display the 3-D molecule structure of Chloroquine in stick style:

3Dmol.js Example - Download CID
3Dmol.js Example - Download CID

Note that the molecule structure data is downloaded with the following PubMed API:

https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/{CID}/SDF?record_type=3d

 

GLViewer Class and Instance Methods

$3Dmol.download('pdb:...', ...) - Download PDB Protein

3Dmol.js Classes and API

⇑⇑ 3Dmol.js FAQ

2023-01-11, 288🔥, 0💬