def run(self): if not self.part.molecules: return for chunk in self.part.molecules: if (chunk.atoms): for atom in chunk.atoms.itervalues(): atom.setOverlayText("?") chunk.showOverlayText = True selection = self.part.selection_for_all() simaspect = sim_aspect(self.part, selection.atomslist(), cmdname_for_messages="CheckAtomTypes", anchor_all_nonmoving_atoms=False) movie = Movie(self.assy) #self._movie = movie writemovie(self.part, movie, 1, simaspect=simaspect, print_sim_warnings=True, cmdname="Simulator", cmd_type="Check AtomTypes", useGromacs=False, background=False, useAMBER=True, typeFeedback=True) self.part.gl_update()
def run(self): if not self.part.molecules: return for chunk in self.part.molecules: if chunk.atoms: for atom in chunk.atoms.itervalues(): atom.setOverlayText("?") chunk.showOverlayText = True selection = self.part.selection_for_all() simaspect = sim_aspect( self.part, selection.atomslist(), cmdname_for_messages="CheckAtomTypes", anchor_all_nonmoving_atoms=False ) movie = Movie(self.assy) # self._movie = movie writemovie( self.part, movie, 1, simaspect=simaspect, print_sim_warnings=True, cmdname="Simulator", cmd_type="Check AtomTypes", useGromacs=False, background=False, useAMBER=True, typeFeedback=True, ) self.part.gl_update()
def run(self): """ Minimize (or Adjust) the Selection or the current Part """ #bruce 050324 made this method from the body of MWsemantics.modifyMinimize # and cleaned it up a bit in terms of how it finds the movie to use. #bruce 050412 added 'Sel' vs 'All' now that we have two different Minimize buttons. # In future the following code might become subclass-specific (and cleaner): ## fyi: this old code was incorrect, I guess since 'in' works by 'is' rather than '==' [not verified]: ## assert self.args in [['All'], ['Sel']], "%r" % (self.args,) #bruce 051129 revising this to clarify it, though command-specific subclasses would be better assert len(self.args) >= 1 cmd_subclass_code = self.args[0] cmd_type = self.kws.get('type', 'Minimize') # one of 'Minimize' or 'Adjust' or 'Adjust Atoms'; determines conv criteria, name [bruce 060705] self.cmd_type = cmd_type # kluge, see comment where used engine = self.kws.get('engine', MINIMIZE_ENGINE_UNSPECIFIED) if (engine == MINIMIZE_ENGINE_UNSPECIFIED): engine = env.prefs[Adjust_minimizationEngine_prefs_key] if (engine == MINIMIZE_ENGINE_GROMACS_FOREGROUND): self.useGromacs = True self.background = False elif (engine == MINIMIZE_ENGINE_GROMACS_BACKGROUND): self.useGromacs = True self.background = True else: self.useGromacs = False self.background = False assert cmd_subclass_code in ['All', 'Sel', 'Atoms'] #e and len(args) matches that? # These words and phrases are used in history messages and other UI text; # they should be changed by specific commands as needed. # See also some computed words and phrases, e.g. self.word_Minimize, # below the per-command if stamements. [bruce 060705] # Also set flags for other behavior which differs between these commands. if cmd_type.startswith('Adjust'): self.word_minimize = "adjust" self.word_minimization = "adjustment" self.word_minimizing = "adjusting" anchor_all_nonmoving_atoms = False pass else: assert cmd_type.startswith('Minimize') self.word_minimize = "minimize" self.word_minimization = "minimization" self.word_minimizing = "minimizing" anchor_all_nonmoving_atoms = True #bruce 080513 revision to implement nfr bug 2848 item 2 # (note: we might decide to add a checkbox for this into the UI, # and just change its default value for Minimize vs Adjust) pass self.word_Minimize = _capitalize_first_word( self.word_minimize) self.word_Minimizing = _capitalize_first_word( self.word_minimizing) if cmd_subclass_code == 'All': cmdtype = _MIN_ALL cmdname = "%s All" % self.word_Minimize elif cmd_subclass_code == 'Sel': cmdtype = _MIN_SEL cmdname = "%s Selection" % self.word_Minimize elif cmd_subclass_code == 'Atoms': #bruce 051129 added this case for Local Minimize (extending a kluge -- needs rewrite to use command-specific subclass) cmdtype = _LOCAL_MIN cmdname = "%s Atoms" % self.word_Minimize #bruce 060705; some code may assume this is always Adjust Atoms, as it is # self.args is parsed later else: assert 0, "unknown cmd_subclass_code %r" % (cmd_subclass_code,) self.cmdname = cmdname #e in principle this should come from a subclass for the specific command [bruce 051129 comment] startmsg = cmdname + ": ..." del cmd_subclass_code # remove model objects inserted only for feedback from prior runs # (both because it's a good feature, and to avoid letting them # mess up this command) [bruce 080520] from simulation.runSim import part_contains_pam_atoms # kluge to use this function for this purpose # (it's called later for other reasons) hasPAM_junk = part_contains_pam_atoms( self.part, kill_leftover_sim_feedback_atoms = True ) self.part.assy.update_parts() ###k is this always safe or good? # Make sure some chunks are in the part. # (Valid for all cmdtypes -- Minimize only moves atoms, even if affected by jigs.) if not self.part.molecules: # Nothing in the part to minimize. env.history.message(greenmsg(cmdname + ": ") + redmsg("Nothing to %s." % self.word_minimize)) return if cmdtype == _MIN_SEL: selection = self.part.selection_from_glpane() # compact rep of the currently selected subset of the Part's stuff if not selection.nonempty(): msg = greenmsg(cmdname + ": ") + redmsg("Nothing selected.") + \ " (Use %s All to %s the entire Part.)" % (self.word_Minimize, self.word_minimize) #e might need further changes for Minimize Energy, if it's confusing that Sel/All is a dialog setting then env.history.message( msg) return elif cmdtype == _LOCAL_MIN: from operations.ops_select import selection_from_atomlist junk, atomlist, ntimes_expand = self.args selection = selection_from_atomlist( self.part, atomlist) #e in cleaned up code, selection object might come from outside selection.expand_atomset(ntimes = ntimes_expand) # ok if ntimes == 0 # Rationale for adding monovalent atoms to the selection before # instantiating the sim_aspect # # (Refer to comments for sim_aspect.__init__.) Why is it safe to add # monovalent atoms to a selection? Let's look at what happens during a # local minimization. # # While minimizing, we want to simulate as if the entire rest of the # part is grounded, and only our selection of atoms is free to move. The # most obvious approach would be to minimize all the atoms in the part # while applying anchors to the atoms that aren't in the selection. But # minimizing all the atoms, especially if the selection is small, is very # wasteful. Applying the simulator to atoms is expensive and we want to # minimize as few atoms as possible. # # [revision, bruce 080513: this discussion applies for Adjust, # but the policy for Minimize is being changed to always include # all atoms, even if most of them are anchored, # re nfr bug 2848 item 2.] # # A more economical approach is to anchor the atoms for two layers going # out from the selection. The reason for going out two layers, and not just # one layer, is that we need bond angle terms to simulate accurately. When # we get torsion angles we will probably want to bump this up to three # layers. [Now we're doing three layers -- bruce 080507] # # Imagine labeling all the atoms in the selection with zero. Then take the # set of unlabeled atoms that are bonded to a zero-labeled atom, and label # all the atoms in that set with one. Next, take the set of yet-unlabeled # atoms that are bonded to a one-labeled atom, and label the atoms in that # set with two. The atoms labeled one and two become our first and second # layers, and we anchor them during the minimization. # # In sim_aspect.__init__, the labels for zero, one and two correspond # respectively to membership in the dictionaries self._moving_atoms, # self._boundary1_atoms, and self._boundary2_atoms. # # If an atom in the selection is anchored, we don't need to go two layers # out from that atom, only one layer. So we can label it with one, even # though it's a member of the selection and would normally be labeled with # zero. The purpose in doing this is to give the simulator a few less atoms # to worry about. # # If a jig includes one of the selected atoms, but additionally includes # atoms outside the selection, then it may not be obvious how to simulate # that jig. For the present, the only jig that counts in a local # minimization is an anchor, because all the other jigs are too complicated # to simulate. # # The proposed fix here has the effect that monovalent atoms bonded to # zero-labeled atoms are also labeled zero, rather than being labeled one, # so they are allowed to move. Why is this OK to do? # # (1) Have we violated the assumption that the rest of the part is locked # down? Yes, as it applies to those monovalent atoms, but they are # presumably acceptable violations, since bug 1240 is regarded as a bug. # # (2) Have we unlocked any bond lengths or bond angles that should remain # locked? Again, only those which involve (and necessarily end at) the # monovalent atoms in question. The same will be true when we introduce # torsion terms. # # (3) Have we lost any ground on the jig front? If a jig includes one or # more of the monovalent atoms, possibly - but the only jigs we are # simulating in this case is anchors, and those will be handled correctly. # Remember that anchored atoms are only extended one layer, not two, but # with a monovalent atom bonded to a selected atom, no extension is # possible at all. # # One can debate about whether bug 1240 should be regarded as a bug. But # having accepted it as a bug, one cannot object to adding these monovalents # to the original selection. # # wware 060410 bug 1240 atoms = selection.selatoms for atom in atoms.values(): # enumerate the monovalents bonded to atom for atom2 in filter(lambda atom: not atom.is_singlet(), atom.baggageNeighbors()): atoms[atom2.key] = atom2 else: assert cmdtype == _MIN_ALL selection = self.part.selection_for_all() # like .selection_from_glpane() but for all atoms presently in the part [bruce 050419] # no need to check emptiness, this was done above self.selection = selection #e might become a feature of all CommandRuns, at some point # At this point, the conditions are met to try to do the command. env.history.message(greenmsg( startmsg)) #bruce 050412 doing this earlier # Disable some QActions (menu items/toolbar buttons) during minimize. self.win.disable_QActions_for_sim(True) try: simaspect = sim_aspect( self.part, selection.atomslist(), cmdname_for_messages = cmdname, anchor_all_nonmoving_atoms = anchor_all_nonmoving_atoms ) #bruce 051129 passing cmdname # note: atomslist gets atoms from selected chunks, not only selected atoms # (i.e. it gets atoms whether you're in Select Atoms or Select Chunks mode) # history message about singlets written as H (if any); #bruce 051115 updated comment: this is used for both Minimize All and Minimize Selection as of long before 051115; # for Run Sim this code is not used (so this history message doesn't go out for it, though it ought to) # but the bug254 X->H fix is done (though different code sets the mapping flag that makes it happen). nsinglets_H = simaspect.nsinglets_H() if nsinglets_H: #bruce 051209 this message code is approximately duplicated elsewhere in this file info = fix_plurals( "(Treating %d bondpoint(s) as Hydrogens, during %s)" % (nsinglets_H, self.word_minimization) ) env.history.message( info) nsinglets_leftout = simaspect.nsinglets_leftout() assert nsinglets_leftout == 0 # for now # history message about how much we're working on; these atomcounts include singlets since they're written as H nmoving = simaspect.natoms_moving() nfixed = simaspect.natoms_fixed() info = fix_plurals( "(%s %d atom(s)" % (self.word_Minimizing, nmoving)) if nfixed: them_or_it = (nmoving == 1) and "it" or "them" if anchor_all_nonmoving_atoms: msg2 = "holding remaining %d atom(s) fixed" % nfixed else: msg2 = "holding %d atom(s) fixed around %s" % (nfixed, them_or_it) info += ", " + fix_plurals(msg2 ) info += ")" env.history.message( info) self.doMinimize(mtype = 1, simaspect = simaspect) # mtype = 1 means single-frame XYZ file. # [this also sticks results back into the part] #self.doMinimize(mtype = 2) # 2 = multi-frame DPB file. finally: self.win.disable_QActions_for_sim(False) simrun = self._movie._simrun #bruce 050415 klugetower if not simrun.said_we_are_done: env.history.message("Done.") return
def run(self): """ Minimize (or Adjust) the Selection or the current Part """ #bruce 050324 made this method from the body of MWsemantics.modifyMinimize # and cleaned it up a bit in terms of how it finds the movie to use. #bruce 050412 added 'Sel' vs 'All' now that we have two different Minimize buttons. # In future the following code might become subclass-specific (and cleaner): ## fyi: this old code was incorrect, I guess since 'in' works by 'is' rather than '==' [not verified]: ## assert self.args in [['All'], ['Sel']], "%r" % (self.args,) #bruce 051129 revising this to clarify it, though command-specific subclasses would be better assert len(self.args) >= 1 cmd_subclass_code = self.args[0] cmd_type = self.kws.get('type', 'Minimize') # one of 'Minimize' or 'Adjust' or 'Adjust Atoms'; determines conv criteria, name [bruce 060705] self.cmd_type = cmd_type # kluge, see comment where used engine = self.kws.get('engine', MINIMIZE_ENGINE_UNSPECIFIED) if (engine == MINIMIZE_ENGINE_UNSPECIFIED): engine = env.prefs[Adjust_minimizationEngine_prefs_key] if (engine == MINIMIZE_ENGINE_GROMACS_FOREGROUND): self.useGromacs = True self.background = False elif (engine == MINIMIZE_ENGINE_GROMACS_BACKGROUND): self.useGromacs = True self.background = True else: self.useGromacs = False self.background = False assert cmd_subclass_code in ['All', 'Sel', 'Atoms'] #e and len(args) matches that? # These words and phrases are used in history messages and other UI text; # they should be changed by specific commands as needed. # See also some computed words and phrases, e.g. self.word_Minimize, # below the per-command if stamements. [bruce 060705] # Also set flags for other behavior which differs between these commands. if cmd_type.startswith('Adjust'): self.word_minimize = "adjust" self.word_minimization = "adjustment" self.word_minimizing = "adjusting" anchor_all_nonmoving_atoms = False pass else: assert cmd_type.startswith('Minimize') self.word_minimize = "minimize" self.word_minimization = "minimization" self.word_minimizing = "minimizing" anchor_all_nonmoving_atoms = True #bruce 080513 revision to implement nfr bug 2848 item 2 # (note: we might decide to add a checkbox for this into the UI, # and just change its default value for Minimize vs Adjust) pass self.word_Minimize = _capitalize_first_word(self.word_minimize) self.word_Minimizing = _capitalize_first_word(self.word_minimizing) if cmd_subclass_code == 'All': cmdtype = _MIN_ALL cmdname = "%s All" % self.word_Minimize elif cmd_subclass_code == 'Sel': cmdtype = _MIN_SEL cmdname = "%s Selection" % self.word_Minimize elif cmd_subclass_code == 'Atoms': #bruce 051129 added this case for Local Minimize (extending a kluge -- needs rewrite to use command-specific subclass) cmdtype = _LOCAL_MIN cmdname = "%s Atoms" % self.word_Minimize #bruce 060705; some code may assume this is always Adjust Atoms, as it is # self.args is parsed later else: assert 0, "unknown cmd_subclass_code %r" % (cmd_subclass_code, ) self.cmdname = cmdname #e in principle this should come from a subclass for the specific command [bruce 051129 comment] startmsg = cmdname + ": ..." del cmd_subclass_code # remove model objects inserted only for feedback from prior runs # (both because it's a good feature, and to avoid letting them # mess up this command) [bruce 080520] from simulation.runSim import part_contains_pam_atoms # kluge to use this function for this purpose # (it's called later for other reasons) hasPAM_junk = part_contains_pam_atoms( self.part, kill_leftover_sim_feedback_atoms=True) self.part.assy.update_parts() ###k is this always safe or good? # Make sure some chunks are in the part. # (Valid for all cmdtypes -- Minimize only moves atoms, even if affected by jigs.) if not self.part.molecules: # Nothing in the part to minimize. env.history.message( greenmsg(cmdname + ": ") + redmsg("Nothing to %s." % self.word_minimize)) return if cmdtype == _MIN_SEL: selection = self.part.selection_from_glpane( ) # compact rep of the currently selected subset of the Part's stuff if not selection.nonempty(): msg = greenmsg(cmdname + ": ") + redmsg("Nothing selected.") + \ " (Use %s All to %s the entire Part.)" % (self.word_Minimize, self.word_minimize) #e might need further changes for Minimize Energy, if it's confusing that Sel/All is a dialog setting then env.history.message(msg) return elif cmdtype == _LOCAL_MIN: from operations.ops_select import selection_from_atomlist junk, atomlist, ntimes_expand = self.args selection = selection_from_atomlist( self.part, atomlist ) #e in cleaned up code, selection object might come from outside selection.expand_atomset(ntimes=ntimes_expand) # ok if ntimes == 0 # Rationale for adding monovalent atoms to the selection before # instantiating the sim_aspect # # (Refer to comments for sim_aspect.__init__.) Why is it safe to add # monovalent atoms to a selection? Let's look at what happens during a # local minimization. # # While minimizing, we want to simulate as if the entire rest of the # part is grounded, and only our selection of atoms is free to move. The # most obvious approach would be to minimize all the atoms in the part # while applying anchors to the atoms that aren't in the selection. But # minimizing all the atoms, especially if the selection is small, is very # wasteful. Applying the simulator to atoms is expensive and we want to # minimize as few atoms as possible. # # [revision, bruce 080513: this discussion applies for Adjust, # but the policy for Minimize is being changed to always include # all atoms, even if most of them are anchored, # re nfr bug 2848 item 2.] # # A more economical approach is to anchor the atoms for two layers going # out from the selection. The reason for going out two layers, and not just # one layer, is that we need bond angle terms to simulate accurately. When # we get torsion angles we will probably want to bump this up to three # layers. [Now we're doing three layers -- bruce 080507] # # Imagine labeling all the atoms in the selection with zero. Then take the # set of unlabeled atoms that are bonded to a zero-labeled atom, and label # all the atoms in that set with one. Next, take the set of yet-unlabeled # atoms that are bonded to a one-labeled atom, and label the atoms in that # set with two. The atoms labeled one and two become our first and second # layers, and we anchor them during the minimization. # # In sim_aspect.__init__, the labels for zero, one and two correspond # respectively to membership in the dictionaries self._moving_atoms, # self._boundary1_atoms, and self._boundary2_atoms. # # If an atom in the selection is anchored, we don't need to go two layers # out from that atom, only one layer. So we can label it with one, even # though it's a member of the selection and would normally be labeled with # zero. The purpose in doing this is to give the simulator a few less atoms # to worry about. # # If a jig includes one of the selected atoms, but additionally includes # atoms outside the selection, then it may not be obvious how to simulate # that jig. For the present, the only jig that counts in a local # minimization is an anchor, because all the other jigs are too complicated # to simulate. # # The proposed fix here has the effect that monovalent atoms bonded to # zero-labeled atoms are also labeled zero, rather than being labeled one, # so they are allowed to move. Why is this OK to do? # # (1) Have we violated the assumption that the rest of the part is locked # down? Yes, as it applies to those monovalent atoms, but they are # presumably acceptable violations, since bug 1240 is regarded as a bug. # # (2) Have we unlocked any bond lengths or bond angles that should remain # locked? Again, only those which involve (and necessarily end at) the # monovalent atoms in question. The same will be true when we introduce # torsion terms. # # (3) Have we lost any ground on the jig front? If a jig includes one or # more of the monovalent atoms, possibly - but the only jigs we are # simulating in this case is anchors, and those will be handled correctly. # Remember that anchored atoms are only extended one layer, not two, but # with a monovalent atom bonded to a selected atom, no extension is # possible at all. # # One can debate about whether bug 1240 should be regarded as a bug. But # having accepted it as a bug, one cannot object to adding these monovalents # to the original selection. # # wware 060410 bug 1240 atoms = selection.selatoms for atom in atoms.values(): # enumerate the monovalents bonded to atom for atom2 in filter(lambda atom: not atom.is_singlet(), atom.baggageNeighbors()): atoms[atom2.key] = atom2 else: assert cmdtype == _MIN_ALL selection = self.part.selection_for_all() # like .selection_from_glpane() but for all atoms presently in the part [bruce 050419] # no need to check emptiness, this was done above self.selection = selection #e might become a feature of all CommandRuns, at some point # At this point, the conditions are met to try to do the command. env.history.message( greenmsg(startmsg)) #bruce 050412 doing this earlier # Disable some QActions (menu items/toolbar buttons) during minimize. self.win.disable_QActions_for_sim(True) try: simaspect = sim_aspect( self.part, selection.atomslist(), cmdname_for_messages=cmdname, anchor_all_nonmoving_atoms=anchor_all_nonmoving_atoms) #bruce 051129 passing cmdname # note: atomslist gets atoms from selected chunks, not only selected atoms # (i.e. it gets atoms whether you're in Select Atoms or Select Chunks mode) # history message about singlets written as H (if any); #bruce 051115 updated comment: this is used for both Minimize All and Minimize Selection as of long before 051115; # for Run Sim this code is not used (so this history message doesn't go out for it, though it ought to) # but the bug254 X->H fix is done (though different code sets the mapping flag that makes it happen). nsinglets_H = simaspect.nsinglets_H() if nsinglets_H: #bruce 051209 this message code is approximately duplicated elsewhere in this file info = fix_plurals( "(Treating %d bondpoint(s) as Hydrogens, during %s)" % (nsinglets_H, self.word_minimization)) env.history.message(info) nsinglets_leftout = simaspect.nsinglets_leftout() assert nsinglets_leftout == 0 # for now # history message about how much we're working on; these atomcounts include singlets since they're written as H nmoving = simaspect.natoms_moving() nfixed = simaspect.natoms_fixed() info = fix_plurals("(%s %d atom(s)" % (self.word_Minimizing, nmoving)) if nfixed: them_or_it = (nmoving == 1) and "it" or "them" if anchor_all_nonmoving_atoms: msg2 = "holding remaining %d atom(s) fixed" % nfixed else: msg2 = "holding %d atom(s) fixed around %s" % (nfixed, them_or_it) info += ", " + fix_plurals(msg2) info += ")" env.history.message(info) self.doMinimize(mtype=1, simaspect=simaspect) # mtype = 1 means single-frame XYZ file. # [this also sticks results back into the part] #self.doMinimize(mtype = 2) # 2 = multi-frame DPB file. finally: self.win.disable_QActions_for_sim(False) simrun = self._movie._simrun #bruce 050415 klugetower if not simrun.said_we_are_done: env.history.message("Done.") return