-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Measure distance between two atoms | ||
================================================= | ||
|
||
This sample shows how add support for measuring the distance between two atoms. | ||
|
||
Usage | ||
-------------------------------------------------- | ||
|
||
Click on two atoms to measure the distance between them. After clicking the second atom, a line will be drawn that connects the two atoms with the distance displayed in a label. | ||
|
||
.. pv-sample:: | ||
|
||
<script> | ||
var parent = document.getElementById('viewer'); | ||
var viewer = pv.Viewer(parent, | ||
{ width : 300, height : 300, antialias : true }); | ||
|
||
pv.io.fetchPdb('_static/1crn.pdb', function(structure) { | ||
viewer.on('viewerReady', function() { | ||
viewer.cartoon('crambin', structure); | ||
viewer.autoZoom(); | ||
}); | ||
}); | ||
|
||
var lastAtom = null; | ||
|
||
|
||
// register click handler that does all the distance-measure-foo | ||
viewer.addListener('click', function(picked) { | ||
if (picked === null) return; | ||
var target = picked.target(); | ||
if (target.qualifiedName === undefined) { | ||
return; | ||
} | ||
var node = picked.node(); | ||
var view = node.structure().createEmptyView(); | ||
if (lastAtom !== null) { | ||
// remove distance-related objects from previous distance | ||
// measurements. | ||
viewer.rm('dist.*'); | ||
var g = viewer.customMesh('dist.line'); | ||
var midPoint = pv.vec3.clone(lastAtom.pos()); | ||
pv.vec3.add(midPoint, midPoint, target.pos()); | ||
pv.vec3.scale(midPoint, midPoint, 0.5); | ||
// add a tube to connect the two atoms | ||
g.addTube(lastAtom.pos(), target.pos(), 0.1, | ||
{ cap : true, color : 'white' }); | ||
var d = pv.vec3.distance(lastAtom.pos(), target.pos()); | ||
var l = viewer.label('dist.label', d.toFixed(2), midPoint); | ||
lastAtom = null; | ||
} else { | ||
lastAtom = target; | ||
view.addAtom(target); | ||
} | ||
node.setSelection(view); | ||
viewer.requestRedraw(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ PV Usage Code Samples | |
sample-static-label | ||
sample-3d-label | ||
sample-custom-mesh | ||
sample-measure-distance |