Ejemplo n.º 1
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
Ejemplo n.º 2
0
def loadrestrt(root, amber_prmtop, messages):
    """ Finds a file to load as a restart """
    type_list = [('Inpcrd', '*.inpcrd'), ('Inpcrd', '*.crd'),
                 ('Restart', '*.restrt'), ('Restart', '*.rst7'),
                 ('All Files', '*')]
    fname = file_chooser('Amber Coordinate File', type_list)
    if fname: 
        action = actions.loadRestrt(amber_prmtop, ArgumentList(fname))
        messages.write('%s\n' % action)
        action.execute()
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def guiapp():
    from parmed import load_file
    from parmed.utils.six.moves import tkinter as tk
    from parmed.utils.six.moves.tkinter_messagebox import showerror
    from optparse import OptionParser
    from os.path import exists, split
    from parmed.tools.exceptions import ParmError
    from parmed import __version__
    from parmed.tools.gui.guitools import ParmedApp
    from parmed.tools.gui.guifiletools import file_chooser
    from parmed.tools.logos import Logo
    from parmed.tools.actions import Action
    from parmed.tools.parmlist import ParmList
    import sys
    
    debug = False
    
    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)
    
    # Launch the root window
    root = tk.Tk()
    root.resizable(True, True)

    # Replace the default excepthook with mine
    sys.excepthook = excepthook

    # See if we were provided a topology file on the command-line
    parser = OptionParser(usage = '%prog [<prmtop>]')
    parser.add_option('-d', '--debug', dest='debug', default=False, 
                      action='store_true', help='Show detailed tracebacks ' +
                      'when an error is detected.')
    opt, args = parser.parse_args()

    debug = opt.debug

    # If the user provided a CL argument, that is the prmtop_name. Otherwise,
    # open up a file choosing dialog box to get the input from the user
    if len(args) == 0:
        prmtop_name = file_chooser('Topology')
    elif len(args) == 1:
        prmtop_name = args[0]
    else:
        sys.stderr.write('Unknown command-line options. Ignoring\n')
        prmtop_name = file_chooser('Topology')

    # If we chose no prmtop file, 
    if not prmtop_name: raise ParmError('No prmtop chosen!')

    # Load the amber prmtop and check for errors
    amber_prmtop = ParmList()
    parm = load_file(prmtop_name)
    amber_prmtop.add_parm(parm)

    # Make this overwritable -- the all of the file save boxes will ask the user
    # for verification before saving over an existing file. There's no need for
    # the AmberParm security layer.
    Action.overwrite = True

    fname = split(prmtop_name)[1]
    root.title('xParmED: Editing/viewing [%s] Choose an operation' % fname)

    # Now build the action list on root
    app = ParmedApp(root, amber_prmtop)
    app.pack(fill=tk.BOTH, expand=1)
    root.mainloop()

    print('Thank you for using xParmEd!\n%s' % Logo())
Ejemplo n.º 5
0
 def callback():
     file_chooser('C4 Parameter File',
             extensions=[('All files', '*')], set_var=var)
Ejemplo n.º 6
0
def guiapp():
    from parmed import load_file
    from parmed.utils.six.moves import tkinter as tk
    from parmed.utils.six.moves.tkinter_messagebox import showerror
    from optparse import OptionParser
    from os.path import split
    from parmed.tools.exceptions import ParmError
    from parmed.tools.gui.guitools import ParmedApp
    from parmed.tools.gui.guifiletools import file_chooser
    from parmed.tools.logos import Logo
    from parmed.tools.actions import Action
    from parmed.tools.parmlist import ParmList
    import sys

    debug = False

    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)

    # Launch the root window
    root = tk.Tk()
    root.resizable(True, True)

    # Replace the default excepthook with mine
    sys.excepthook = excepthook

    # See if we were provided a topology file on the command-line
    parser = OptionParser(usage='%prog [<prmtop>]')
    parser.add_option('-d',
                      '--debug',
                      dest='debug',
                      default=False,
                      action='store_true',
                      help='Show detailed tracebacks ' +
                      'when an error is detected.')
    opt, args = parser.parse_args()

    debug = opt.debug

    # If the user provided a CL argument, that is the prmtop_name. Otherwise,
    # open up a file choosing dialog box to get the input from the user
    if len(args) == 0:
        prmtop_name = file_chooser('Topology')
    elif len(args) == 1:
        prmtop_name = args[0]
    else:
        sys.stderr.write('Unknown command-line options. Ignoring\n')
        prmtop_name = file_chooser('Topology')

    # If we chose no prmtop file,
    if not prmtop_name: raise ParmError('No prmtop chosen!')

    # Load the amber prmtop and check for errors
    amber_prmtop = ParmList()
    parm = load_file(prmtop_name)
    amber_prmtop.add_parm(parm)

    # Make this overwritable -- the all of the file save boxes will ask the user
    # for verification before saving over an existing file. There's no need for
    # the AmberParm security layer.
    Action.overwrite = True

    fname = split(prmtop_name)[1]
    root.title('xParmED: Editing/viewing [%s] Choose an operation' % fname)

    # Now build the action list on root
    app = ParmedApp(root, amber_prmtop)
    app.pack(fill=tk.BOTH, expand=1)
    root.mainloop()

    print('Thank you for using xParmEd!\n%s' % Logo())