Esempio n. 1
0
def scale(root, amber_prmtop, messages):
    """ Allows us to scale every value in a particular prmtop section """
    # The spinbox is sent with the Spinbox, label, and then a list of all of the
    # values to give to it
    changeable_properties = ['Spinbox', 'Property to scale']
    for flag in amber_prmtop.parm.flag_list:
        if amber_prmtop.parm.formats[flag].type is float:
            changeable_properties.append(flag)
    widget_list = [changeable_properties, ('Entry', 'Value to scale by')]
    # We need 2 string variables, then get the description
    var_list = [StringVar(), StringVar()]
    description = 'Scales all values in a given prmtop section by a given value'
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('scale', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = var_list[0].get() or var_list[1].get()
    if not vars_found: return
    # If we did, store them and pass it to the class
    var_list = [v.get() for v in var_list]
    try:
        action = actions.scale(amber_prmtop, ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    action.execute()
    messages.write('%s\n' % action)
Esempio n. 2
0
def changeljsingletype(root, amber_prmtop, messages):
    """ Changes radius/well depth of a single LJ type given by the mask """
    # We need a mask, radius, and well depth
    widget_list = [('MaskEntry', 'Mask to change LJ Type'),
                   ('Entry', 'New LJ Radius'), ('Entry', 'New LJ Depth')]
    var_list = [StringVar(), StringVar(), StringVar()]
    description = "Change a given atom type's LJ radius and well depth"
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('changeLJSingleType', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # addljtype expects any _non_specified variables to be None
    var_list = [v.get() for v in var_list]
    for i, v in enumerate(var_list):
        if not v: var_list[i] = None
    # If we did, store them and pass it to the class
    try:
        action = actions.changeLJSingleType(amber_prmtop,
                                                  ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    messages.write('%s\n' % action)
    action.execute()
Esempio n. 3
0
 def excepthook(exception_type, exception_value, tb):
     """ Default exception handler """
     import traceback
     if debug: traceback.print_tb(tb)
     showerror('Fatal Error','%s: %s' % (exception_type.__name__,
                                         exception_value))
     sys.exit(1)
Esempio n. 4
0
 def excepthook(exception_type, exception_value, tb):
     """ Default exception handler """
     import traceback
     if debug: traceback.print_tb(tb)
     showerror('Fatal Error',
               '%s: %s' % (exception_type.__name__, exception_value))
     sys.exit(1)
Esempio n. 5
0
def strip(root, amber_prmtop, messages):
    """ Strips a mask from the topology file """
    # We need a mask, new radius, new epsilon, and for chamber topologies,
    # a new radius-1-4 and epsilon-1-4. Don't add the latter ones until we
    # know if we have a chamber prmtop or not.
    widget_list = [('MaskEntry', 'Atoms to strip from topology')]
    # We need 5 string variables, then get the description. 
    var_list = [StringVar()]
    description=('Strips the selected atoms from the topology file. All\n'
                 'remaining atoms and parameters remain unchanged. Any\n'
                 'parameters associated with stripped atoms are removed.')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('strip', amber_prmtop,
                                        widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    var = var_list[0]
    if not var.get(): return
    try:
        action = actions.strip(amber_prmtop, ArgumentList(var.get()))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    messages.write('%s\n' % action)
    action.execute()
Esempio n. 6
0
def printinfo(root, amber_prmtop, messages):
    """ Prints all of the info in a given FLAG """
    # Set up the window
    # variables we need for printInfo
    widget_list = [('Entry', '%FLAG you want info from')]
    # Variable list -- we need a single string
    var_list = [StringVar()]
    # description
    description = ' '.join(actions.printInfo.__doc__.split())
    cmd_window = _guiwidgets.ActionWindow('printInfo', amber_prmtop,
                                widget_list, var_list, description)
    cmd_window.wait_window()
    # Make sure we didn't cancel (or just press OK with no input), or just leave
    var = var_list[0].get()
    if not var: return
    # Now that we did something, do it
    action = actions.printInfo(amber_prmtop, ArgumentList(var))
    if not action.found:
        showerror('Not Found!', '%%FLAG %s not found!' % var.upper())
        return

    window = Toplevel(root)
    window.resizable(True, True)
    window.title('%%FLAG %s Info in %s' % (var.upper(), amber_prmtop))
    text = _guiwidgets.ExitingScrollText(window, None, spacing3=5, padx=5,
                                            pady=5, width=82, height=20)
    text.write(action)
    text.pack(fill=BOTH, expand=1)
    window.wait_window()

    messages.write('Wrote info for flag %s\n' % var.upper())
Esempio n. 7
0
def change(root, amber_prmtop, messages):
    """ Allows us to change a specific atomic property """
    # The spinbox is sent with the Spinbox, label, and then a list of all of the
    # values to give to it
    widget_list = [('Spinbox', 'Property to change', 'CHARGE', 'MASS',
                    'RADII', 'SCREEN', 'ATOM_NAME', 'AMBER_ATOM_TYPE',
                    'ATOM_TYPE_INDEX', 'ATOMIC_NUMBER'),
                    ('MaskEntry', 'Atoms to change'),
                    ('Entry', 'New Value for Property')]
    # We need 3 string variables, then get the description
    var_list = [StringVar(), StringVar(), StringVar()]
    description = 'Changes the property of given atoms to a new value'
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('change', amber_prmtop,
                        widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # If we did, store them and pass it to the class
    var_list = [v.get() for v in var_list]
    try:
        action = actions.change(amber_prmtop, ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    action.execute()
    messages.write('%s\n' % action)
Esempio n. 8
0
def changelj14pair(root, amber_prmtop, messages):
    """ Changes specific 1-4 Lennard Jones pairs """
    # Only good for chamber topologies
    if not amber_prmtop.parm.chamber:
        showerror('Incompatible',
                  'changeLJ14Pair is only valid for chamber topologies!')
        return
    # variables we need for changelj14pair
    widget_list = [('MaskEntry', 'Atom(s) Type 1 Mask'),
                   ('MaskEntry', 'Atom(s) Type 2 Mask'),
                   ('Entry', 'Combined Radius'),
                   ('Entry', 'Combined Well Depth')]
    # Variable list -- we need 2 masks and 2 floats
    var_list = [StringVar(), StringVar(), StringVar(), StringVar()]
    # description
    description = ' '.join(actions.changeLJ14Pair.__doc__.split())
    cmd_window = _guiwidgets.ActionWindow('changeLJ14Pair', amber_prmtop,
                                widget_list, var_list, description)
    cmd_window.wait_window()
    # Make sure we didn't cancel (or just press OK with no input), or just leave
    vars_exist = True in [bool(v.get()) for v in var_list]
    if not vars_exist: return
    # Now that we did something, do it
    var_list = [v.get() for v in var_list]
    try:
        action=actions.changeLJ14Pair(amber_prmtop,ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
Esempio n. 9
0
def addexclusions(root, amber_prmtop, messages):
    """ Adds atoms to other atoms' exclusion list """
    # We need 2 masks
    widget_list = [('MaskEntry', 'Atoms to add excluded atoms to'),
                   ('MaskEntry', 'Atoms to exclude from other mask')]
    # We have 2 mask variables
    var_list = [StringVar(), StringVar()]
    # Description
    description = ('Allows you to add arbitrary excluded atoms to exclusion\n'
                   'lists. This omits all non-bonded interactions in the '
                   'direct-space\ncalculation, but does not omit interactions '
                   'from adjacent cells in\nperiodic simulations')
    cmd_window = _guiwidgets.ActionWindow('addExclusions', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
   
    # Bail out if we didn't get any variables
    if not True in [bool(v.get()) for v in var_list]: return
   
    var_list = [v.get() for v in var_list]
    try:
        act = actions.addExclusions(amber_prmtop, ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    act.execute()
    messages.write('%s\n' % act)
Esempio n. 10
0
def addpdb(root, amber_prmtop, messages):
    """ Adds PDB information to a topology file """

    # Get the name of the file
    type_list = [('PDB', '*.pdb'), ('All Files', '*')]
    fname = file_chooser('PDB File', type_list)
    if not fname: return

    widget_list = [('Checkbutton', 'Require all residue names be consistent.'),
                   ('Checkbutton', 'Print element names in %FLAG ELEMENT'),
                   ('Checkbutton', 'Print all insertion codes, even if all are '
                                   'blank.')]
   
    var_list = [StringVar(value='no') for i in range(3)]
    description = ('Adds information from the PDB file (e.g., CHAIN IDs) to '
                   'the topology file')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('addPDB', amber_prmtop, widget_list,
                                          var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    newvars = [fname]
    # If we did, pass them through
    if var_list[0] == 'yes': newvars.append('strict')
    if var_list[1] == 'yes': newvars.append('elem')
    if var_list[1] == 'yes': newvars.append('allicodes')
    try:
        action = actions.addPDB(amber_prmtop, ArgumentList(newvars))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 11
0
def changeljpair(root, amber_prmtop, messages):
    """ Changes a pair-wise LJ interaction for pre-combined epsilon/Rmin """
    # The variables we need for changeljpair
    widget_list = [('MaskEntry', 'Atom(s) Type 1 Mask'),
                   ('MaskEntry', 'Atom(s) Type 2 Mask'),
                   ('Entry', 'Combined Radius'),
                   ('Entry', 'Combined Well Depth')]
    # Variable list -- we need 2 masks and 2 floats
    var_list = [StringVar(), StringVar(), StringVar(), StringVar()]
    # description
    description = ' '.join(actions.changeLJPair.__doc__.split())
    cmd_window = _guiwidgets.ActionWindow('changeLJPair', amber_prmtop,
                                widget_list, var_list, description)
    cmd_window.wait_window()
    # Make sure we didn't cancel (or just press OK with no input), or just leave
    vars_exist = True in [bool(v.get()) for v in var_list]
    if not vars_exist: return
    # Now that we did something, do it
    var_list = [v.get() for v in var_list]
    try:
        action = actions.changeLJPair(amber_prmtop,ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
Esempio n. 12
0
def setangle(root, amber_prmtop, messages):
    """ Sets (adds or changes) an angle in the topology file """
    # We need 3 masks, a force constant, and an equilibrium angle
    widget_list = [('MaskEntry', 'First atom in angle'),
                   ('MaskEntry', 'Second (middle) atom in angle'),
                   ('MaskEntry', 'Third atom in angle'),
                   ('Entry', 'Force constant (kcal/mol rad**2)'),
                   ('Entry', 'Equilibrium Angle (Degrees)')]
    # We need 5 variables
    var_list = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
    description = ('Sets an angle in the topology file with the given Force '
                   'constant in kcal/mol/rad**2\nand the given equilibrium '
                   'angle in Degrees. All three masks must specify only a\n'
                   'single atom. If the angle exists, it will be replaced. If '
                   'it doesn\'t, it will be added.')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('setAngle', amber_prmtop, 
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # If we did, pass them through
    var_list = [v.get() for v in var_list]
    try:
        action = actions.setAngle(amber_prmtop, ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 13
0
def deletedihedral(root, amber_prmtop, messages):
    """ Deletes a dihedral between 4 given atoms """
    # We need 4 masks
    widget_list = [('MaskEntry', 'First (end) atom in dihedral'),
                   ('MaskEntry', 'Second (middle) atom in dihedral'),
                   ('MaskEntry', 'Third (middle) atom in dihedral'),
                   ('MaskEntry', 'Fourth (end) atom in dihedral')]
    # We need 4 variables
    var_list = [StringVar() for i in range(4)]
    description = ('Deletes dihedrals between the atoms specified in mask1, ' +
                   'mask2, mask3, and mask4.\nIt will try to match dihedrals ' +
                   'only in the order given or reverse order. Dihedrals are\n' +
                   'specified by atom N in mask1, mask2, mask3, and mask4,' +
                   'where N is the selected\natom in that mask.')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('deleteDihedral', amber_prmtop, 
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # If we did, pass them through
    var_list = [v.get() for v in var_list]
    try:
        action = actions.deleteDihedral(amber_prmtop,
                                              ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 14
0
def printdihedrals(root, amber_prmtop, messages):
    """ Prints dihedrals containing atoms from a given mask """
    widget_list = [('MaskEntry', 'Atoms 1 or Atoms to analyze for dihedrals'),
                   ('MaskEntry', 'Atoms 2 (optional)'),
                   ('MaskEntry', 'Atoms 3 (optional)'),
                   ('MaskEntry', 'Atoms 4 (optional)')]
    var_list = [StringVar(), StringVar(), StringVar(), StringVar()]
    desc = 'Prints all dihedrals containing at least 1 atom in the given mask'
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('printDihedrals', amber_prmtop,
                                          widget_list, var_list, desc)
    cmd_window.wait_window()
    # See if we got any variables back
    var = ' '.join([x.get() for x in var_list]).strip()
    if not var: return
    try:
        action = actions.printDihedrals(amber_prmtop, ArgumentList(var))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    messages.write('Printed DIHEDRALs for %s\n' % var)
    # Now make the text window
    window = Toplevel(root)
    window.resizable(True, True)
    window.title('DIHEDRAL list in %s' % amber_prmtop.parm)
    text = _guiwidgets.ExitingScrollText(window, None, spacing3=5, padx=5,
                                         pady=5, width=140, height=20)
    text.pack(fill=BOTH, expand=1)
    text.write(action)
    window.wait_window()
Esempio n. 15
0
def printljtypes(root, amber_prmtop, messages):
    """
    Prints all of the atoms that have the same LJ type as atoms in a given mask
    """
    # We need a mask
    widget_list = [('MaskEntry', 'Atom Mask or Atom Type Name')]
    var_list = [StringVar()]
    description = ('Get a list of all atoms that share a common LJ type')
    cmd_window = _guiwidgets.ActionWindow('printLJTypes', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
   
    var = var_list[0].get()

    # Bail out if we didn't get any variables
    if not var: return
   
    # Instantiate our action
    try:
        action = actions.printLJTypes(amber_prmtop, ArgumentList(var))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return

    # Create our Info window
    window = Toplevel(root)
    window.resizable(True, True)
    window.title('LJ Type List')
    text = _guiwidgets.ExitingScrollText(window, None, spacing3=2, padx=5,
                                         pady=5, width=45, height=30)
    text.pack(fill=BOTH, expand=1)
    text.write(action)
    messages.write('Printed LJ types for [%s]\n' % var)
    window.wait_window()
Esempio n. 16
0
def printljmatrix(root, amber_prmtop, messages):
    """ Prints A/B matrix coefficients """
    # We need 1 mask
    widget_list = [('MaskEntry', 'Atoms To Find LJ Interactions')]
    # We need 1 variable
    var_list = [StringVar()]
    description = ('Prints all A- and B-Coefficient elements between the atom '
                   'types specified in <mask> with every other atom type')
    # Create the window, open it, and wait for it to close
    cmd_window = _guiwidgets.ActionWindow('printLJMatrix', amber_prmtop, 
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # Bail out if we cancelled or something
    var = var_list[0].get()
    if not var: return
    try:
        action = actions.printLJMatrix(amber_prmtop, ArgumentList(var))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return

    # Create our Info window
    window = Toplevel(root)
    window.resizable(True, True)
    window.title('LJ Type List')
    text = _guiwidgets.ExitingScrollText(window, None, spacing3=2, padx=5,
                                         pady=5, width=45, height=30)
    text.pack(fill=BOTH, expand=1)
    text.write(action)
    messages.write('Printed LJ matrix for types [%s]\n' % var)
    window.wait_window()
Esempio n. 17
0
def gui_action_dispatcher(root, amber_prmtop, action_name, messages):
    """ 
    Dispatches all of the GUI actions given the action name. This is the only
    externally accessible *thing* in this module. All of the action-specific
    methods are in _guiactions with the same name as those found in
    parmed.tools.actions 
    """

    if not hasattr(_guiactions, action_name.lower()):
        showerror("Not Implemented.", action_name + " is not implemented in xParmEd! Use parmed instead.")
        return None

    # Call the function to establish our action
    getattr(_guiactions, action_name.lower())(root, amber_prmtop, messages)
Esempio n. 18
0
def gui_action_dispatcher(root, amber_prmtop, action_name, messages):
    """ 
    Dispatches all of the GUI actions given the action name. This is the only
    externally accessible *thing* in this module. All of the action-specific
    methods are in _guiactions with the same name as those found in
    parmed.tools.actions 
    """

    if not hasattr(_guiactions, action_name.lower()):
        showerror('Not Implemented.', action_name + 
                  ' is not implemented in xParmEd! Use parmed instead.')
        return None

    # Call the function to establish our action
    getattr(_guiactions, action_name.lower())(root, amber_prmtop, messages)
Esempio n. 19
0
def add12_6_4(root, amber_prmtop, messages):
    """
    Adds 12-6-4 potential energy terms
    """
    # The variables we need for changeljpair
    widget_list = [('MaskEntry', 'Divalent ion mask'),
                   ('FileSelector', 'C4 Parameter File'),
                   ('Entry', 'Water model (instead of C4 Params)'),
                   ('FileSelector', 'Pol. Param File'),
                   ('Entry', 'tunfactor')]
    # Variable list -- we need 2 masks and 2 floats
    var_list = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
    var_list[1].set('Pick C4 File')
    var_list[3].set('Pick Pol. File')
    # description
    description = ('Add the r^-4 Lennard-Jones parameter for the 12-6-4 term\n'
                   'used typically for multi-valent ion parameters')
    cmd_window = _guiwidgets.ActionWindow('add12_6_4', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # Make sure we didn't cancel (or just press OK with no input), or just leave
    vars_exist = [bool(v.get()) for v in var_list]
    if var_list[1].get() == 'Pick C4 File': vars_exist[1] = False
    if var_list[3].get() == 'Pick Pol. File': vars_exist[3] = False
    if vars_exist[1] and vars_exist[2]:
        showerror('Cannot select both C4 parameter file AND water model')
        return
    vars_exist = True in vars_exist
    if not vars_exist: return
    # Now that we did something, do it
    var_list = [v.get() for v in var_list]
    if var_list[1] == 'Pick C4 File': var_list[1] = ''
    if var_list[3] == 'Pick Pol. File': var_list[3] = ''
    args = [var_list[0]]
    if var_list[1]: args.extend(['c4file', var_list[1]])
    if var_list[2]: args.extend(['watermodel', var_list[2]])
    if var_list[3]: args.extend(['polfile', var_list[3]])
    if var_list[4]: args.extend(['tunfactor', var_list[4]])
    try:
        action = actions.add12_6_4(amber_prmtop, ArgumentList(args))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
Esempio n. 20
0
def adddihedral(root, amber_prmtop, messages):
    """ Adds a dihedral (improper, multiterm, or normal) to the prmtop """
    # We need 4 masks, phi_k, periodicity, phase, scee/scnb, dihedral type
    widget_list = [
            ('MaskEntry', 'First (end) atom in dihedral'),
            ('MaskEntry', 'Second (middle) atom in dihedral'),
            ('MaskEntry', 'Third (middle) atom in dihedral'),
            ('MaskEntry', 'Fourth (end) atom in dihedral'),
            ('Entry', 'Phi Force constant (kcal/mol)'),
            ('Entry', 'Periodicity'),
            ('Entry', 'Phase (Degrees)'),
            ('Entry', 'EEL scaling factor'),
            ('Entry', 'VDW scaling factor'),
            ('Spinbox', 'Dihedral type', 'normal', 'improper')
    ]
    # We need 10 variables
    var_list = [StringVar() for i in range(10)]
    description = ('Adds a dihedral in the topology file with the given Phi '
                   'Force constant in kcal/mol the\ngiven phase in Degrees '
                   'and the given periodicity. All masks must specify only \n'
                   'a single atom. The default Amber values for SCEE/SCNB are '
                   '1.2 and 2.0, respectively.\nSee the Amber manual for '
                   'details about normal, multiterm, and improper dihedrals')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('setDihedral', amber_prmtop, 
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # If we did, pass them through
    var_list = [v.get() for v in var_list]
    # Fill scee/scnb in with default values
    if var_list[7] is None: var_list[7] = '1.2'
    if var_list[8] is None: var_list[8] = '2.0'
    # The last argument is a keyword, so append that, then swap the last 2 args
    var_list.insert(9, 'type')
    try:
        action = actions.addDihedral(amber_prmtop, ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 21
0
def addcoarsegrain(root, amber_prmtop, messages):
    """ Adds coarse graining to topology file via Lula's algo """
    # This implementation doesn't exist anywhere yet, so disable it
    showerror('Warning', 'This functionality is not implemented in Amber yet!')
    return

    # We need a file
    fname = file_chooser('Coarse Grain Parameter', 
                         [('Coarse Grain Parameters', '*.cgparm'),
                          ('All Files', '*')]
    )
   
    if not fname: return

    try:
        action = actions.addCoarseGrain(amber_prmtop, ArgumentList(fname))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 22
0
def addljtype(root, amber_prmtop, messages):
    """ Turns given mask into a new LJ atom type """
    # We need a mask, new radius, new epsilon, and for chamber topologies,
    # a new radius-1-4 and epsilon-1-4. Don't add the latter ones until we
    # know if we have a chamber prmtop or not.
    widget_list = [('MaskEntry', 'Atoms to make new LJ Type'),
                   ('Entry', 'New Radius (default old radius)'),
                   ('Entry', 'New Depth (default old depth)')]
    # We need 5 string variables, then get the description. 
    var_list = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
    description=('Turns given mask into a new LJ atom type. Uses the radius\n'
                 'and well depth from the first atom type in <mask> if none\n'
                 'are provided.')
    if amber_prmtop.parm.chamber:
        widget_list += [('Entry', 'New Radius for 1-4 Terms'),
                        ('Entry', 'New Depth for 1-4 Terms')]
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('addLJType', amber_prmtop,
                        widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # addljtype expects any _non_specified variables to be None
    var_list = [v.get().strip() for v in var_list]
    kw_var_list = [var_list[0]]
    if var_list[1]: kw_var_list.extend(['radius', var_list[1]])
    if var_list[2]: kw_var_list.extend(['epsilon', var_list[2]])
    if amber_prmtop.parm.chamber and var_list[3]:
        kw_var_list.extend(['radius_14', var_list[3]])
    if amber_prmtop.parm.chamber and var_list[4]:
        kw_var_list.extend(['epsilon_14', var_list[4]])
    try:
        action = actions.addLJType(amber_prmtop,ArgumentList(kw_var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    action.execute()
    messages.write('%s\n' % action)
Esempio n. 23
0
def scnb(root, amber_prmtop, messages):
    # We need a value
    widget_list = [('Entry', '1-4 van der Waals Scaling Factor')]
    var_list = [StringVar()]
    description = 'Adjust the scaling factor for 1-4 van der Waals interactions'

    cmd_window = _guiwidgets.ActionWindow('scee', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
   
    var = var_list[0].get()

    # Bail out if we didn't get any variables
    if not var: return

    try:
        action = actions.scnb(amber_prmtop, ArgumentList(var))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    messages.write('%s\n' % action)
    action.execute()
Esempio n. 24
0
def definesolvent(root, amber_prmtop, messages):
    """ Allows you to define what you consider to be solvent molecules """
    # We need a molecule #
    widget_list = [('Entry', 'List of solvent residue names')]
    var_list = [StringVar()]
    description =('Tell ParmEd that these residue names should be considered\n'
                  'to be solvent residues. This should be a comma-delimited '
                  'list')
    cmd_window = _guiwidgets.ActionWindow('defineSolvent', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    var = var_list[0].get()
    if not var: return
    # addljtype expects any _non_specified variables to be None
    try:
        action = actions.defineSolvent(amber_prmtop, ArgumentList(var))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 25
0
def timerge(root, amber_prmtop, messages):
    """ Merges a topology file with 2 molecules into a single prmtop for TI """
    # We need coordinates, so check for that
    if amber_prmtop.parm.coords is None:
        showerror(root, 'tiMerge requires you to load coordinates first!')
        return
    # We need 2 masks, a force constant, and an equilibrium distance
    widget_list = [('MaskEntry', 'Mask Unique to Lambda = 0'),
                   ('MaskEntry', 'Mask Unique to Lambda = 1'),
                   ('MaskEntry', 'Softcore Mask in Lambda = 0'),
                   ('MaskEntry', 'Softcore Mask in Lambda = 1'),
                   ('MaskEntry', 'Softcore Mols NOT to Merge (Lambda=0)'),
                   ('MaskEntry', 'Softcore Mols NOT to Merge (Lambda=1)'),
                   ('Entry', 'Tolerance')]
    # We need 4 variables
    var_list = [StringVar() for i in range(7)]
    var_list[6].set('0.0001')
    description = 'Merges 2 molecules inside a prmtop for use with softcore TI'
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('tiMerge', amber_prmtop, 
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = True in [bool(v.get()) for v in var_list]
    if not vars_found: return
    # If we did, pass them through
    var_list = [v.get() for v in var_list]
    if not var_list[6].strip():
        var_list[6] = '0.0001'
    var_list.insert(6, 'tol')
    actions.tiMerge.output = messages
    try:
        action = actions.tiMerge(amber_prmtop, ArgumentList(var_list))
        messages.write('%s\n' % action)
        action.execute()
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
Esempio n. 26
0
def changeprotstate(root, amber_prmtop, messages):
    # We need a mask and a state
    widget_list = [('MaskEntry', 'Residue to change protonation state'),
                   ('Entry', 'Protonation state to change to')]
    var_list = [StringVar(), StringVar()]
    description=('Changes the protonation state of a titratable residue that\n'
                 'can be treated with constant pH MD in Amber.')
    cmd_window = _guiwidgets.ActionWindow('changeProtState', amber_prmtop,
                        widget_list, var_list, description)
    cmd_window.wait_window()
   
    # Bail out if we didn't get any variables
    if not True in [bool(v.get()) for v in var_list]: return
   
    var_list = [v.get() for v in var_list]
    try:
        action = actions.changeProtState(amber_prmtop, 
                                               ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    action.execute()
    messages.write('%s\n' % action)
Esempio n. 27
0
def hmassrepartition(root, amber_prmtop, messages):
    """
    Repartitions mass by making H-atoms heavier and attached heteroatoms
    lighter by the same amount to preserve the same total mass
    """
    # The spinbox is sent with the Spinbox, label, and then a list of all of the
    # values to give to it
    widget_list = [('Entry', 'New hydrogen mass (daltons)'),
                   ('Checkbutton', 'Repartition waters?')]
    # We need 2 string variables, then get the description
    var_list = [StringVar(value='3.024'), StringVar(value='no')]
    description = ('Repartitions atomic masses to keep total mass the same '
                   'while increasing H-atom masses to allow using a larger '
                   'time step.')
    # Create the window, open it, then wait for it to close
    cmd_window = _guiwidgets.ActionWindow('HMassChange', amber_prmtop,
                                          widget_list, var_list, description)
    cmd_window.wait_window()
    # See if we got any variables back
    vars_found = var_list[0].get() or var_list[1].get()
    if not vars_found: return
    # If we did, store them and pass it to the class
    var_list = [v.get() for v in var_list]
    # Convert the check button into the correct keyword
    if var_list[1] == 'yes':
        var_list[1] = 'dowater'
    else:
        var_list[1] = ''
    try:
        action = actions.HMassRepartition(amber_prmtop,
                                                ArgumentList(var_list))
    except Exception as err:
        showerror('Unexpected Error!', '%s: %s' % (type(err).__name__, err))
        return
    action.execute()
    messages.write('%s\n' % action)
Esempio n. 28
0
    def __init__(self, title, amber_prmtop, widget_list, var_list, description):
        self.cancelled = False
        self.var_list = var_list
        # widget_list: list of tuples having widget class names and description
        # title: title of the window (action name)
        # var_list: list of variables that go in each widget
        # description: Description to print out on the window
        BaseParmedWindow.__init__(self, amber_prmtop, title)
        # Add description label
        main_desc = Label(self, text=description, justify=CENTER,
                          pady=5, padx=10)
        main_desc.grid(column=0, row=0, sticky=N+S+E+W)
        # Make a frame to put all of our widgets in
        main_frame = Frame(self, padx=10, pady=5)
        # Now add all of our widgets to our 
        for i, wtemp in enumerate(widget_list):
            wname, wdesc = wtemp[0], wtemp[1]
            var = var_list[i]
            local_frame = Frame(main_frame)
            if wname == 'MaskEntry':
                mywidget = MaskEntry(local_frame, self.amber_prmtop,
                                     wdesc, var, self)
                mywidget.grid(row=0, column=0, sticky=N+S+E+W)
            elif wname == 'Entry':
                wlab = Label(local_frame, text=wdesc)
                wlab.grid(row=0, column=0, sticky=N+S+E+W)
                mywidget = Entry(local_frame, width=40, textvariable=var)
                mywidget.grid(row=1, column=0, sticky=N+S+E+W)
            elif wname == 'Spinbox':
                wlab = Label(local_frame, text=wdesc)
                wlab.grid(row=0, column=0, sticky=N+S+E+W)
                mywidget = Spinbox(local_frame, textvariable=var,
                                   values=wtemp[2:])
                mywidget.grid(row=1, column=0, sticky=N+S+E+W)
            elif wname == 'Checkbutton':
                mywidget = Checkbutton(local_frame, text=wdesc, variable=var,
                                    onvalue='yes', offvalue='no')
                mywidget.grid(row=0, column=0, sticky=N+S+E+W)
            elif wname == 'FileSelector':
                def callback():
                    file_chooser('C4 Parameter File',
                            extensions=[('All files', '*')], set_var=var)
                mywidget = Button(local_frame, textvariable=var,
                                  command=callback)
                wlab = Label(local_frame, text=wdesc)
                wlab.grid(row=0, column=0, sticky=N+S+E+W)
                mywidget.grid(row=1, column=0, sticky=N+S+E+W)
            else:
                showerror('Error!', '%s not implemented yet!' % wname)
                self.destroy()
            local_frame.grid(row=i//2, column=i%2, sticky=N+S+E+W)

        # Now pack the main frame
        main_frame.grid(column=0, row=1, sticky=N+S+E+W)
        # Now make the OK and Cancel buttons
        ok_can_frame = Frame(self, padx=10, pady=5)
        ok_can_frame.grid(column=0, row=2)
        button = Button(ok_can_frame, text='OK', command=self.destroy)
        button.grid(row=0, column=0, sticky=N+S+E+W, padx=10)
        button = Button(ok_can_frame, text='Cancel', command=self.cancel)
        button.grid(row=0, column=1, sticky=N+S+E+W, padx=10)