Giter Site home page Giter Site logo

Comments (6)

awaterho avatar awaterho commented on August 11, 2024

Sounds like it would be very possible, it should be fast enough.

You would need to create a selection based on the mousemove event, such as

var rect = pv_viewer.boundingClientRect();
var picked = pv_viewer.pick({ x : event.clientX - rect.left, y : event.clientY - rect.top });

And then selectWithin a PV structure (eg protein = pv_viewer.get('model01').structure() )

protein.selectWithin( picked.target(),
{
radius: 4,
matchResidues:true
});

matchResidues extends the atoms found in the radius to be a complete residue.

from pv.

wjs20 avatar wjs20 commented on August 11, 2024

Hi Awaterho

Thanks! I gave the above code a try but I ran into an error.

my code

<html>
<head>
  <title>Dengue Virus Methyl Transferase</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<div id=viewer></div>
</body>
<div id='picked-atom-name' style='text-align:center;'>&nbsp;</div>
<script type='text/javascript' src='pv.min.js'></script>

<script>
  var parent = document.getElementById('viewer');
  var viewer = pv.Viewer(parent,{ width : 600, height : 600, antialias : true });
  
  parent.addEventListener('mousemove', function(event) {
    var rect = viewer.boundingClientRect();
    var picked = viewer.pick({ x : event.clientX - rect.left,
                              y : event.clientY - rect.top });
    var protein = viewer.get('protein').structure()
    protein.selectWithin(picked.target(), {radius: 4, matchResidues: true});
    viewer.requestRedraw();
  });

  pv.io.fetchPdb('6umt.pdb', function(structure) {

    viewer.on('viewerReady', function() {
      viewer.cartoon('protein', structure);
      viewer.centerOn(structure);
    });
  });
</script>

the error

Uncaught TypeError: b.eachAtom is not a function
    at j.selectWithin (pv.min.js:12:13235)
    at HTMLDivElement.<anonymous> (index.html:59:13)
(anonymous) @ pv.min.js:12
(anonymous) @ index.html:59

Do you know what might be causing the issue?

from pv.

wjs20 avatar wjs20 commented on August 11, 2024

Also when I am not hovering directly over an atom, I get this error.

Uncaught TypeError: Cannot read properties of null (reading 'target')
    at HTMLDivElement.<anonymous> (index.html:58:24)
(anonymous) @ index.html:58

I want to pick up atoms within a given radius of my mouse even if my mouse if not on top of an atom. Is this possible?

from pv.

awaterho avatar awaterho commented on August 11, 2024

You have to check that picked is not null, it will only exist if the mouse is directly over an atom.

from pv.

awaterho avatar awaterho commented on August 11, 2024

I see the selectWithin only works on residues, not atoms. So Some minor changes -

<script>
  var parent = document.getElementById('viewer');
  var viewer = pv.Viewer(parent,{ width : 600, height : 600, antialias : true });
  var protein = null;

  parent.addEventListener('mousemove', function(event) {
    var rect = viewer.boundingClientRect();
    var picked = viewer.pick({ x : event.clientX - rect.left,
                              y : event.clientY - rect.top });
    if(!picked)
      return;

    viewer.rm('surrounding')
    var surrounding = protein.selectWithin(picked.target().residue(), {radius: 4, matchResidues: true});
    viewer.lines('surrounding', surrounding);
    viewer.requestRedraw();
  });

  pv.io.fetchPdb('6umt.pdb', function(structure) {

    viewer.on('viewerReady', function() {
      viewer.cartoon('protein', structure);
      viewer.centerOn(structure);
      protein = viewer.get('protein').structure();
    });
  });
</script>

from pv.

wjs20 avatar wjs20 commented on August 11, 2024

That worked quite nicely. Thanks! :)

from pv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.