Collections:
addModel() - Add Model from Data
How to create a model from a molecule data string with 3Dmol.js addModel() methods?
✍: FYIcenter.com
viewer.addModel() method in the $3Dmol.GLViewer class
allows you to create a model from molecule data string:
{$3Dmol.GLViewer} addModel(data, format, options) -> {$3Dmol.GLModel}
Here is an HTML code example, View-PDB-Online.html, that create a model from molecule data obtained an AJAX call.
<html><head>
<script src="/3Dmol-min.js"></script>
<style>
.mol-container {width: 400px; height: 400px; position: relative;}
</style>
</head>
<body>
<div id="container-01" class="mol-container"></div>
<script>
$(function() {
let element = $('#container-01');
let config = { backgroundColor: 'grey' };
let viewer = $3Dmol.createViewer( element, config );
let pdbUri = 'https://files.rcsb.org/download/1YCR.pdb';
jQuery.ajax( pdbUri, {
success: function(data) {
let v = viewer;
v.addModel( data, "pdb" ); /* load data */
v.setStyle({}, {cartoon: {color: 'spectrum'}}); /* style all atoms */
v.zoomTo(); /* set camera */
v.render(); /* render scene */
},
error: function(hdr, status, err) {
console.error( "Failed to load PDB " + pdbUri + ": " + err );
},
});
});
</script>
</body></html>
This example HTML code will display a protein structure as shown below:
⇐ addSphere() - Create Spheres
⇑⇑ 3Dmol.js FAQ
2023-01-11, 843🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1000336 SMILES: CC(=C)C1CCC2(C1C3CCC4C5( CCC(=O)C(C5CCC4(C3(CC2)C )C)(C)C)C)...
Molecule Summary: ID: FYI-1001005 SMILES: C12CCC(C)3C(C(C)CCC(=O)O )CCC3C1C(I)CC(C)1CCCCC12 CReceived...
Molecule Summary: ID: FYI-1002294 Names: InChIKey: LEYWMXGGVZTHDM-UHFFFAOYS A-NSMILES: COc1ccc2c(c1)...
Molecule Summary: ID: FYI-1004117 Names: InChIKey: QBCUUJGHWFKMDC-UHFFFAOYS A-NSMILES: CC(=O)C(O)Cc1...
Molecule Summary: ID: FYI-1000286 SMILES: [R2]C([C@H](CC1=CC=CO1)N [R1])=OReceived at FYIcenter.com ...