Beispiel #1
0
 def recompute_center_axis(
         self,
         glpane):  #bruce 060120 replaced los arg with glpane re bug 1344
     # try to point in direction of prior axis, or along line of sight if no old axis (self.axis is V(0,0,0) then)
     nears = [self.axis, glpane.lineOfSight, glpane.down]
     pos = A(map(lambda a: a.posn(), self.atoms))
     self.center = sum(pos) / len(pos)
     relpos = pos - self.center
     from geometry.geometryUtilities import compute_heuristic_axis
     axis = compute_heuristic_axis(relpos,
                                   'normal',
                                   already_centered=True,
                                   nears=nears,
                                   dflt=None)
     if not axis:
         #e warning? I think so... BTW we pass dflt = None to make the warning come out more often;
         # I don't know if we'd need to check for it here if we didn't.
         env.history.message(
             orangemsg(
                 "Warning: motor axis chosen arbitrarily since atom arrangement doesn't suggest one."
             ))
         #k can this come out too often during movie-playing? No, because we don't recompute axis then at all.
         axis = glpane.lineOfSight
     self.axis = axis
     self.assy.changed(
     )  #bruce 060116 fix unreported bug analogous to bug 1331
     self._initial_posns = None  #bruce 050518; needed in RotaryMotor, harmless in others
     return
Beispiel #2
0
    def viewNormalTo(self): # 
        """
        Set view to the normal vector of the plane defined by 3 or more
        selected atoms or a jig's (Motor or RectGadget) axis.
        """
        cmd = greenmsg("Set View Normal To: ")

        chunks = self.assy.selmols
        jigs = self.assy.getSelectedJigs()
        atoms = self.assy.selatoms_list()

        #following fixes bug 1748 ninad 061003. 
        if len(chunks) > 0 and len(atoms) == 0:
            # Even though chunks have an axis, it is not necessarily the same
            # axis attr stored in the chunk.  Get the chunks atoms and let
            # compute_heuristic_axis() recompute them.
            for c in range(len(chunks)):
                atoms += chunks[c].atoms.values()
        elif len(jigs) == 1 and len(atoms) == 0:
            # Warning: RectGadgets have no atoms.  We handle this special case below.
            atoms = jigs[0].atoms 
        elif len(atoms) < 3:
            # There is a problem when allowing only 2 selected atoms. 
            # Changing requirement to 3 atoms fixes bug 1418. mark 060322
            msg = redmsg("Please select some atoms, jigs, and/or chunks, covering at least 3 atoms")
            print "ops_view.py len(atoms) = ", len(atoms)
            env.history.message(cmd + msg)
            return

        # This check is needed for jigs that have no atoms.  Currently, this 
        # is the case for RectGadgets (ESP Image and Grid Plane) only.
        if len(atoms):
            pos = A( map( lambda a: a.posn(), atoms ) )
            nears = [ self.glpane.out, self.glpane.up ]
            axis = compute_heuristic_axis( pos, 'normal', already_centered = False, nears = nears, dflt = None )
        else: # We have a jig with no atoms.
            axis = jigs[0].getaxis() # Get the jig's axis.
            # If axis is pointing into the screen, negate (reverse) axis.
            if dot(axis, self.glpane.lineOfSight) > 0:
                axis = -axis

        if not axis:
            msg = orangemsg( "Warning: Normal axis could not be determined. No change in view." )
            env.history.message(cmd + msg)
            return

        # Compute the destination quat (q2).
        q2 = Q(V(0,0,1), axis)
        q2 = q2.conj()

        self.glpane.rotateView(q2)

        info = 'View set to normal vector of the plane defined by the selected atoms.'
        env.history.message(cmd + info)
Beispiel #3
0
    def viewNormalTo_NEW(self):
        """
        Set view to the normal vector of the plane defined by 3 or more
        selected atoms or a jig's (Motor or RectGadget) axis.
        """
        # This implementation has two serious problems:
        #   1. it selects a normal based on the atoms and not the axis of a jig (e.g. a moved rotary motor).
        #   2. doesn't consider selected jigs that have no atoms.
        # Bruce and I will discuss this and determine the best implem.
        # For A7, I've decide to use the original version. This version will be reinstated in A8
        # after fixing these problems. mark 060322.

        cmd = greenmsg("Set View Normal To: ")

        atoms = self.assy.getSelectedAtoms()

        if len(atoms) < 3:
            # There is a problem when allowing only 2 selected atoms.
            # Changing requirement to 3 atoms fixes bug 1418. mark 060322
            msg = redmsg(
                "Please select some atoms, jigs, and/or chunks, covering at least 3 atoms"
            )
            env.history.message(cmd + msg)
            return

        pos = A(map(lambda a: a.posn(),
                    atoms))  # build list of atom xyz positions.
        nears = [self.glpane.out, self.glpane.up]
        axis = compute_heuristic_axis(pos,
                                      'normal',
                                      already_centered=False,
                                      nears=nears,
                                      dflt=None)

        if not axis:
            msg = orangemsg(
                "Warning: Normal axis could not be determined. No change in view."
            )
            env.history.message(cmd + msg)
            return

        # Compute the destination quat (q2).
        q2 = Q(V(0, 0, 1), axis)
        q2 = q2.conj()

        self.glpane.rotateView(q2)

        info = 'View set to normal of the plane defined by the selection.'
        env.history.message(cmd + info)
Beispiel #4
0
 def recompute_center_axis(self, glpane): #bruce 060120 replaced los arg with glpane re bug 1344
     # try to point in direction of prior axis, or along line of sight if no old axis (self.axis is V(0,0,0) then)
     nears = [self.axis, glpane.lineOfSight, glpane.down]
     pos = A( map( lambda a: a.posn(), self.atoms ) )
     self.center = sum(pos)/len(pos)
     relpos = pos - self.center
     from geometry.geometryUtilities import compute_heuristic_axis
     axis = compute_heuristic_axis( relpos, 'normal', already_centered = True, nears = nears, dflt = None )
     if not axis:
         #e warning? I think so... BTW we pass dflt = None to make the warning come out more often;
         # I don't know if we'd need to check for it here if we didn't.
         env.history.message( orangemsg( "Warning: motor axis chosen arbitrarily since atom arrangement doesn't suggest one." ))
             #k can this come out too often during movie-playing? No, because we don't recompute axis then at all.
         axis = glpane.lineOfSight
     self.axis = axis
     self.assy.changed()  #bruce 060116 fix unreported bug analogous to bug 1331
     self._initial_posns = None #bruce 050518; needed in RotaryMotor, harmless in others
     return
Beispiel #5
0
    def viewNormalTo_NEW(self):
        """
        Set view to the normal vector of the plane defined by 3 or more
        selected atoms or a jig's (Motor or RectGadget) axis.
        """
        # This implementation has two serious problems:
        #   1. it selects a normal based on the atoms and not the axis of a jig (e.g. a moved rotary motor).
        #   2. doesn't consider selected jigs that have no atoms.
        # Bruce and I will discuss this and determine the best implem.  
        # For A7, I've decide to use the original version. This version will be reinstated in A8
        # after fixing these problems. mark 060322.

        cmd = greenmsg("Set View Normal To: ")

        atoms = self.assy.getSelectedAtoms()

        if len(atoms) < 3:
            # There is a problem when allowing only 2 selected atoms.
            # Changing requirement to 3 atoms fixes bug 1418. mark 060322
            msg = redmsg("Please select some atoms, jigs, and/or chunks, covering at least 3 atoms")
            env.history.message(cmd + msg)
            return

        pos = A( map( lambda a: a.posn(), atoms ) ) # build list of atom xyz positions.
        nears = [ self.glpane.out, self.glpane.up ]
        axis = compute_heuristic_axis( pos, 'normal', already_centered = False, nears = nears, dflt = None )

        if not axis:
            msg = orangemsg( "Warning: Normal axis could not be determined. No change in view." )
            env.history.message(cmd + msg)
            return

        # Compute the destination quat (q2).
        q2 = Q(V(0,0,1), axis)
        q2 = q2.conj()

        self.glpane.rotateView(q2)

        info = 'View set to normal of the plane defined by the selection.'
        env.history.message(cmd + info)