コード例 #1
0
ファイル: _guiactions.py プロジェクト: TengyuMaVandy/ParmEd
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)
コード例 #2
0
ファイル: cpinutil.py プロジェクト: ruanyangry/ParmEd
def main(opt):
    # Check all of the arguments
    if not os.path.exists(opt.prmtop):
        raise AmberError('prmtop file (%s) is missing' % opt.prmtop)

    # Process the arguments that take multiple args
    resstates = process_arglist(opt.resstates, int)
    resnums = process_arglist(opt.resnums, int)
    notresnums = process_arglist(opt.notresnums, int)
    resnames = process_arglist(opt.resnames, str)
    notresnames = process_arglist(opt.notresnames, str)
    minpka = opt.minpka
    maxpka = opt.maxpka

    if not opt.igb in (1, 2, 5, 7, 8):
        raise AmberError('-igb must be 1, 2, 5, 7, or 8!')

    if resnums is not None and notresnums is not None:
        raise AmberError('Cannot specify -resnums and -notresnums together')

    if resnames is not None and notresnames is not None:
        raise AmberError('Cannot specify -resnames and -notresnames together')

    if opt.intdiel != 1 and opt.intdiel != 2:
        raise AmberError('-intdiel must be either 1 or 2 currently')

    # Print warning about old format
    if opt.oldfmt:
        sys.stderr.write(
            'Warning: The old format of the CPIN file can only be used for simulations with temp0=300.0!\n'
            '         You should use the new format for simulations with temperatures other than 300.0 Kelvins\n'
        )

    # Set the list of residue names we will be willing to titrate
    titratable_residues = []
    if notresnames is not None:
        for resname in residues.titratable_residues:
            if resname in notresnames: continue
            titratable_residues.append(resname)
    elif resnames is not None:
        for resname in resnames:
            if not resname in residues.titratable_residues:
                raise AmberError('%s is not a titratable residue!' % resname)
            elif not getattr(residues, resname).typ == "ph":
                raise AmberError('%s is not a pH titratable residue!' %
                                 resname)
            titratable_residues.append(resname)
    else:
        for resname in residues.titratable_residues:
            if getattr(residues, resname).typ == "ph":
                titratable_residues.append(resname)

    solvent_ions = [
        'WAT', 'Na+', 'Br-', 'Cl-', 'Cs+', 'F-', 'I-', 'K+', 'Li+', 'Mg+',
        'Rb+', 'CIO', 'IB', 'MG2'
    ]

    # Filter titratable residues based on min and max pKa
    new_reslist = []
    for res in titratable_residues:
        if getattr(residues, res).pKa < minpka: continue
        if getattr(residues, res).pKa > maxpka: continue
        new_reslist.append(res)
    titratable_residues = new_reslist
    del new_reslist

    # Make sure we still have a couple residues
    if len(titratable_residues) == 0:
        raise AmberError('No titratable residues fit your criteria!')

    # Load the topology file
    parm = AmberParm(opt.prmtop)

    # Replace an un-set notresnums with an empty list so we get __contains__()
    if notresnums is None:
        notresnums = []

    # If we have a list of residue numbers, check that they're all titratable
    if resnums is not None:
        for resnum in resnums:
            if resnum > parm.ptr('nres'):
                raise AmberError('%s only has %d residues. (%d chosen)' %
                                 (parm, parm.ptr('nres'), resnum))
            if resnum <= 0:
                raise AmberError('Cannot select negative residue numbers.')
            resname = parm.parm_data['RESIDUE_LABEL'][resnum - 1]
            if not resname in titratable_residues:
                raise AmberError('Residue number %s [%s] is not titratable' %
                                 (resnum, resname))
    else:
        # Select every residue except those in notresnums
        resnums = []
        for resnum in range(1, parm.ptr('nres') + 1):
            if resnum in notresnums: continue
            resnums.append(resnum)

    solvated = False
    first_solvent = 0
    if 'WAT' in parm.parm_data['RESIDUE_LABEL']:
        solvated = True
        for i, res in enumerate(parm.parm_data['RESIDUE_LABEL']):
            if res in solvent_ions:
                first_solvent = parm.parm_data['RESIDUE_POINTER'][i]
                break
    main_reslist = TitratableResidueList(system_name=opt.system,
                                         solvated=solvated,
                                         first_solvent=first_solvent)
    for resnum in resnums:
        resname = parm.parm_data['RESIDUE_LABEL'][resnum - 1]
        if not resname in titratable_residues: continue
        res = getattr(residues, resname)
        # Filter out termini (make sure the residue in the prmtop has as many
        # atoms as the titratable residue defined in residues.py)
        if resnum == parm.ptr('nres'):
            natoms = (parm.ptr('natom') + 1 -
                      parm.parm_data['RESIDUE_POINTER'][resnum - 1])
        else:
            natoms = (parm.parm_data['RESIDUE_POINTER'][resnum] -
                      parm.parm_data['RESIDUE_POINTER'][resnum - 1])
        if natoms != len(res.atom_list): continue
        # If we have gotten this far, add it to the list.
        main_reslist.add_residue(res, resnum,
                                 parm.parm_data['RESIDUE_POINTER'][resnum - 1])

    # Set the states if requested
    if resstates is not None:
        main_reslist.set_states(resstates)

    # Open the output file
    if opt.output is None:
        output = sys.stdout
    else:
        output = open(opt.output, 'w')

    main_reslist.write_cpin(output, opt.igb, opt.intdiel, opt.oldfmt, "ph")

    if opt.output is not None:
        output.close()

    if solvated:
        if opt.outparm is None:
            has_carboxylate = False
            for res in main_reslist:
                if res is residues.AS4 or res is residues.GL4 or res is residues.PRN:
                    has_carboxylate = True
                    break
            if has_carboxylate:
                sys.stderr.write(
                    'Warning: Carboxylate residues in explicit solvent '
                    'simulations require a modified topology file!\n'
                    'Use the -op flag to print one.\n')
        else:
            changeRadii(parm, 'mbondi2').execute()
            change(parm, 'RADII', ':AS4,GL4,PRN@OD=,OE=,O1=,O2=',
                   1.3).execute()
            parm.overwrite = True
            parm.write_parm(opt.outparm)
    else:
        if opt.outparm is not None:
            sys.stderr.write(
                'A new prmtop is only necessary for explicit solvent '
                'CpHMD/pH-REMD simulations.\n')

    sys.stderr.write('CPIN generation complete!\n')
コード例 #3
0
def main(opt):
    # Check all of the arguments
    if not os.path.exists(opt.prmtop):
        raise AmberError('prmtop file (%s) is missing' % opt.prmtop)

    # Process the arguments that take multiple args
    resstates = process_arglist(opt.resstates, int)
    resnums = process_arglist(opt.resnums, int)
    notresnums = process_arglist(opt.notresnums, int)
    resnames = process_arglist(opt.resnames, str)
    notresnames = process_arglist(opt.notresnames, str)
    minpka = opt.minpka
    maxpka = opt.maxpka

    if not opt.igb in (1, 2, 5, 7, 8):
        raise AmberError('-igb must be 1, 2, 5, 7, or 8!')

    if resnums is not None and notresnums is not None:
        raise AmberError('Cannot specify -resnums and -notresnums together')

    if resnames is not None and notresnames is not None:
        raise AmberError('Cannot specify -resnames and -notresnames together')

    if opt.intdiel != 1 and opt.intdiel != 2:
        raise AmberError('-intdiel must be either 1 or 2 currently')

    # Print warning about old format
    if opt.oldfmt:
        sys.stderr.write('Warning: The old format of the CPIN file can only be used for simulations with temp0=300.0!\n'
                         '         You should use the new format for simulations with temperatures other than 300.0 Kelvins\n')

    # Set the list of residue names we will be willing to titrate
    titratable_residues = []
    if notresnames is not None:
        for resname in residues.titratable_residues:
            if resname in notresnames: continue
            titratable_residues.append(resname)
    elif resnames is not None:
        for resname in resnames:
            if not resname in residues.titratable_residues:
                raise AmberError('%s is not a titratable residue!' % resname)
            elif not getattr(residues, resname).typ == "ph":
                raise AmberError('%s is not a pH-active titratable residue!' % resname)
            titratable_residues.append(resname)
    else:
        for resname in residues.titratable_residues:
            if getattr(residues, resname).typ == "ph":
                titratable_residues.append(resname)

    solvent_ions = ['WAT', 'Na+', 'Br-', 'Cl-', 'Cs+', 'F-', 'I-', 'K+', 'Li+',
                    'Mg+', 'Rb+', 'CIO', 'IB', 'MG2']

    # Filter titratable residues based on min and max pKa
    new_reslist = []
    for res in titratable_residues:
        # @jaimergp: If None values are not filtered out, comparisons
        # will fail in Py3k. This patch was discussed and approved in
        # GitLab issue 122 (@vwcruzeiro, @swails)
        # Error obtained in serial tests in conda-forge builds:
        #       Traceback (most recent call last):
        #         File "/home/conda/amber/bin/cpinutil.py", line 325, in <module>
        #           main(opt)
        #         File "/home/conda/amber/bin/cpinutil.py", line 191, in main
        #           if getattr(residues, res).pKa < minpka: continue
        #       TypeError: '<' not supported between instances of 'NoneType' and 'int'
        #         ./Run.cpin:  Program error
        #       make[1]: *** [test.cpinutil] Error 1
        if getattr(residues, res).pKa is None: continue
        # /@jaimergp
        if getattr(residues, res).pKa < minpka: continue
        if getattr(residues, res).pKa > maxpka: continue
        new_reslist.append(res)
    titratable_residues = new_reslist
    del new_reslist

    # Make sure we still have a couple residues
    if len(titratable_residues) == 0:
        raise AmberError('No titratable residues fit your criteria!')

    # Load the topology file
    parm = AmberParm(opt.prmtop)

    # Replace an un-set notresnums with an empty list so we get __contains__()
    if notresnums is None:
        notresnums = []

    # If we have a list of residue numbers, check that they're all titratable
    if resnums is not None:
        for resnum in resnums:
            if resnum > parm.ptr('nres'):
                raise AmberError('%s only has %d residues. (%d chosen)' %
                                     (parm, parm.ptr('nres'), resnum))
            if resnum <= 0:
                raise AmberError('Cannot select negative residue numbers.')
            resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
            if not resname in titratable_residues:
                raise AmberError('Residue number %s [%s] is not titratable'
                                     % (resnum, resname))
    else:
        # Select every residue except those in notresnums
        resnums = []
        for resnum in range(1, parm.ptr('nres') + 1):
            if resnum in notresnums: continue
            resnums.append(resnum)

    solvated = False
    first_solvent = 0
    if 'WAT' in parm.parm_data['RESIDUE_LABEL']:
        solvated = True
        for i, res in enumerate(parm.parm_data['RESIDUE_LABEL']):
            if res in solvent_ions:
                first_solvent = parm.parm_data['RESIDUE_POINTER'][i]
                break
    main_reslist = TitratableResidueList(system_name=opt.system,
                        solvated=solvated, first_solvent=first_solvent)
    trescnt = 0
    for resnum in resnums:
        resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
        if not resname in titratable_residues: continue
        res = getattr(residues, resname)
        # Filter out termini (make sure the residue in the prmtop has as many
        # atoms as the titratable residue defined in residues.py)
        if resnum == parm.ptr('nres'):
            natoms = (parm.ptr('natom') + 1 -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        else:
            natoms = (parm.parm_data['RESIDUE_POINTER'][resnum] -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        if natoms != len(res.atom_list): continue
        # If we have gotten this far, add it to the list.
        main_reslist.add_residue(res, resnum,
                                 parm.parm_data['RESIDUE_POINTER'][resnum-1])
        trescnt += 1

    # Prints a warning if the number of titratable residues is larger than 50
    if trescnt > 50: sys.stderr.write('Warning: Your CPIN file has more than 50 titratable residues! pmemd and sander have a\n'
                                      '         default limit of 50 titrable residues, thus this CPIN file can only be used\n'
                                      '         if the definitions for this limit are modified at the top of\n'
                                      '         $AMBERHOME/src/pmemd/src/constantph.F90 or $AMBERHOME/AmberTools/src/sander/constantph.F90.\n'
                                      '         AMBER needs to be recompilied after these files are modified.\n')

    # Set the states if requested
    if resstates is not None:
        main_reslist.set_states(resstates)

    # Open the output file
    if opt.output is None:
        output = sys.stdout
    else:
        output = open(opt.output, 'w')

    main_reslist.write_cpin(output, opt.igb, opt.intdiel, opt.oldfmt, "ph")

    if opt.output is not None:
        output.close()

    if solvated:
        if opt.outparm is None:
            has_carboxylate = False
            for res in main_reslist:
                if res is residues.AS4 or res is residues.GL4 or res is residues.PRN:
                    has_carboxylate = True
                    break
            if has_carboxylate:
                sys.stderr.write(
                        'Warning: Carboxylate residues in explicit solvent '
                        'simulations require a modified topology file!\n'
                        '         Use the -op flag to print one.\n'
                )
        else:
            changeRadii(parm, 'mbondi2').execute()
            change(parm, 'RADII', ':AS4,GL4,PRN@OD=,OE=,O1=,O2=', 1.3).execute()
            parm.overwrite = True
            parm.write_parm(opt.outparm)
    else:
        if opt.outparm is not None:
            sys.stderr.write(
                    'A new prmtop is only necessary for explicit solvent '
                    'CpHMD/pH-REMD simulations.\n'
            )

    sys.stderr.write('CPIN generation complete!\n')
コード例 #4
0
ファイル: cpinutil.py プロジェクト: ParmEd/ParmEd
def main(opt):
    # Check all of the arguments
    if not os.path.exists(opt.prmtop):
        raise AmberError('prmtop file (%s) is missing' % opt.prmtop)

    # Process the arguments that take multiple args
    resstates = process_arglist(opt.resstates, int)
    resnums = process_arglist(opt.resnums, int)
    notresnums = process_arglist(opt.notresnums, int)
    resnames = process_arglist(opt.resnames, str)
    notresnames = process_arglist(opt.notresnames, str)
    minpka = opt.minpka
    maxpka = opt.maxpka

    if not opt.igb in (1, 2, 5, 7, 8):
        raise AmberError('-igb must be 1, 2, 5, 7, or 8!')

    if resnums is not None and notresnums is not None:
        raise AmberError('Cannot specify -resnums and -notresnums together')

    if resnames is not None and notresnames is not None:
        raise AmberError('Cannot specify -resnames and -notresnames together')

    if opt.intdiel != 1 and opt.intdiel != 2:
        raise AmberError('-intdiel must be either 1 or 2 currently')

    # Print warning about old format
    if opt.oldfmt:
        sys.stderr.write('Warning: The old format of the CPIN file can only be used for simulations with temp0=300.0!\n'
                         '         You should use the new format for simulations with temperatures other than 300.0 Kelvins\n')

    # Set the list of residue names we will be willing to titrate
    titratable_residues = []
    if notresnames is not None:
        for resname in residues.titratable_residues:
            if resname in notresnames: continue
            titratable_residues.append(resname)
    elif resnames is not None:
        for resname in resnames:
            if not resname in residues.titratable_residues:
                raise AmberError('%s is not a titratable residue!' % resname)
            elif not getattr(residues, resname).typ == "ph":
                raise AmberError('%s is not a pH-active titratable residue!' % resname)
            titratable_residues.append(resname)
    else:
        for resname in residues.titratable_residues:
            if getattr(residues, resname).typ == "ph":
                titratable_residues.append(resname)

    solvent_ions = ['WAT', 'Na+', 'Br-', 'Cl-', 'Cs+', 'F-', 'I-', 'K+', 'Li+',
                    'Mg+', 'Rb+', 'CIO', 'IB', 'MG2']

    # Filter titratable residues based on min and max pKa
    new_reslist = []
    for res in titratable_residues:
        if getattr(residues, res).pKa < minpka: continue
        if getattr(residues, res).pKa > maxpka: continue
        new_reslist.append(res)
    titratable_residues = new_reslist
    del new_reslist

    # Make sure we still have a couple residues
    if len(titratable_residues) == 0:
        raise AmberError('No titratable residues fit your criteria!')

    # Load the topology file
    parm = AmberParm(opt.prmtop)

    # Replace an un-set notresnums with an empty list so we get __contains__()
    if notresnums is None:
        notresnums = []

    # If we have a list of residue numbers, check that they're all titratable
    if resnums is not None:
        for resnum in resnums:
            if resnum > parm.ptr('nres'):
                raise AmberError('%s only has %d residues. (%d chosen)' %
                                     (parm, parm.ptr('nres'), resnum))
            if resnum <= 0:
                raise AmberError('Cannot select negative residue numbers.')
            resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
            if not resname in titratable_residues:
                raise AmberError('Residue number %s [%s] is not titratable'
                                     % (resnum, resname))
    else:
        # Select every residue except those in notresnums
        resnums = []
        for resnum in range(1, parm.ptr('nres') + 1):
            if resnum in notresnums: continue
            resnums.append(resnum)

    solvated = False
    first_solvent = 0
    if 'WAT' in parm.parm_data['RESIDUE_LABEL']:
        solvated = True
        for i, res in enumerate(parm.parm_data['RESIDUE_LABEL']):
            if res in solvent_ions:
                first_solvent = parm.parm_data['RESIDUE_POINTER'][i]
                break
    main_reslist = TitratableResidueList(system_name=opt.system,
                        solvated=solvated, first_solvent=first_solvent)
    trescnt = 0
    for resnum in resnums:
        resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
        if not resname in titratable_residues: continue
        res = getattr(residues, resname)
        # Filter out termini (make sure the residue in the prmtop has as many
        # atoms as the titratable residue defined in residues.py)
        if resnum == parm.ptr('nres'):
            natoms = (parm.ptr('natom') + 1 -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        else:
            natoms = (parm.parm_data['RESIDUE_POINTER'][resnum] -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        if natoms != len(res.atom_list): continue
        # If we have gotten this far, add it to the list.
        main_reslist.add_residue(res, resnum,
                                 parm.parm_data['RESIDUE_POINTER'][resnum-1])
        trescnt += 1

    # Prints a warning if the number of titratable residues is larger than 50
    if trescnt > 50: sys.stderr.write('Warning: Your CPIN file has more than 50 titratable residues! pmemd and sander have a\n'
                                      '         default limit of 50 titrable residues, thus this CPIN file can only be used\n'
                                      '         if the definitions for this limit are modified at the top of\n'
                                      '         $AMBERHOME/src/pmemd/src/constantph.F90 or $AMBERHOME/AmberTools/src/sander/constantph.F90.\n'
                                      '         AMBER needs to be recompilied after these files are modified.\n')

    # Set the states if requested
    if resstates is not None:
        main_reslist.set_states(resstates)

    # Open the output file
    if opt.output is None:
        output = sys.stdout
    else:
        output = open(opt.output, 'w')

    main_reslist.write_cpin(output, opt.igb, opt.intdiel, opt.oldfmt, "ph")

    if opt.output is not None:
        output.close()

    if solvated:
        if opt.outparm is None:
            has_carboxylate = False
            for res in main_reslist:
                if res is residues.AS4 or res is residues.GL4 or res is residues.PRN:
                    has_carboxylate = True
                    break
            if has_carboxylate:
                sys.stderr.write(
                        'Warning: Carboxylate residues in explicit solvent '
                        'simulations require a modified topology file!\n'
                        '         Use the -op flag to print one.\n'
                )
        else:
            changeRadii(parm, 'mbondi2').execute()
            change(parm, 'RADII', ':AS4,GL4,PRN@OD=,OE=,O1=,O2=', 1.3).execute()
            parm.overwrite = True
            parm.write_parm(opt.outparm)
    else:
        if opt.outparm is not None:
            sys.stderr.write(
                    'A new prmtop is only necessary for explicit solvent '
                    'CpHMD/pH-REMD simulations.\n'
            )

    sys.stderr.write('CPIN generation complete!\n')
コード例 #5
0
ファイル: cpinutil.py プロジェクト: TengyuMaVandy/ParmEd
def main(opt):
    # Check all of the arguments
    if not os.path.exists(opt.prmtop):
        raise AmberError('prmtop file (%s) is missing' % opt.prmtop)
   
    # Process the arguments that take multiple args
    resstates = process_arglist(opt.resstates, int)
    resnums = process_arglist(opt.resnums, int)
    notresnums = process_arglist(opt.notresnums, int)
    resnames = process_arglist(opt.resnames, str)
    notresnames = process_arglist(opt.notresnames, str)
    minpka = opt.minpka
    maxpka = opt.maxpka

    if not opt.igb in (2, 5, 8):
        raise AmberError('-igb must be 2, 5, or 8!')
   
    if resnums is not None and notresnums is not None:
        raise AmberError('Cannot specify -resnums and -notresnums together')
   
    if resnames is not None and notresnames is not None:
        raise AmberError('Cannot specify -resnames and -notresnames together')
   
    if opt.intdiel != 1 and opt.intdiel != 2:
        raise AmberError('-intdiel must be either 1 or 2 currently')

    # Set the list of residue names we will be willing to titrate
    titratable_residues = []
    if notresnames is not None:
        for resname in residues.titratable_residues:
            if resname in notresnames: continue
            titratable_residues.append(resname)
    elif resnames is not None:
        for resname in resnames:
            if not resname in residues.titratable_residues:
                raise AmberError('%s is not a titratable residue!' % resname)
            titratable_residues.append(resname)
    else:
        titratable_residues = residues.titratable_residues[:]
   
    solvent_ions = ['WAT', 'Na+', 'Br-', 'Cl-', 'Cs+', 'F-', 'I-', 'K+', 'Li+',
                    'Mg+', 'Rb+', 'CIO', 'IB', 'MG2']
   
    # Filter titratable residues based on min and max pKa
    new_reslist = []
    for res in titratable_residues:
        if getattr(residues, res).pKa < minpka: continue
        if getattr(residues, res).pKa > maxpka: continue
        new_reslist.append(res)
    titratable_residues = new_reslist
    del new_reslist
   
    # Make sure we still have a couple residues
    if len(titratable_residues) == 0:
        raise AmberError('No titratable residues fit your criteria!')
   
    # Load the topology file
    parm = AmberParm(opt.prmtop)
   
    # Replace an un-set notresnums with an empty list so we get __contains__()
    if notresnums is None:
        notresnums = []
   
    # If we have a list of residue numbers, check that they're all titratable
    if resnums is not None:
        for resnum in resnums:
            if resnum > parm.ptr('nres'):
                raise AmberError('%s only has %d residues. (%d chosen)' %
                                     (parm, parm.ptr('nres'), resnum))
            if resnum <= 0:
                raise AmberError('Cannot select negative residue numbers.')
            resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
            if not resname in titratable_residues:
                raise AmberError('Residue number %s [%s] is not titratable'
                                     % (resnum, resname))
    else:
        # Select every residue except those in notresnums
        resnums = []
        for resnum in range(1, parm.ptr('nres') + 1):
            if resnum in notresnums: continue
            resnums.append(resnum)
   
    solvated = False
    first_solvent = 0
    if 'WAT' in parm.parm_data['RESIDUE_LABEL']:
        solvated = True
        for i, res in enumerate(parm.parm_data['RESIDUE_LABEL']):
            if res in solvent_ions:
                first_solvent = parm.parm_data['RESIDUE_POINTER'][i]
                break
    main_reslist = TitratableResidueList(system_name=opt.system, 
                        solvated=solvated, first_solvent=first_solvent)
    for resnum in resnums:
        resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
        if not resname in titratable_residues: continue
        res = getattr(residues, resname)
        # Filter out termini (make sure the residue in the prmtop has as many
        # atoms as the titratable residue defined in residues.py)
        if resnum == parm.ptr('nres'):
            natoms = (parm.ptr('natom') + 1 -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        else:
            natoms = (parm.parm_data['RESIDUE_POINTER'][resnum] -
                      parm.parm_data['RESIDUE_POINTER'][resnum-1])
        if natoms != len(res.atom_list): continue
        # If we have gotten this far, add it to the list.
        main_reslist.add_residue(res, resnum,
                                 parm.parm_data['RESIDUE_POINTER'][resnum-1])
   
    # Set the states if requested
    if resstates is not None:
        main_reslist.set_states(resstates)
   
    # Open the output file
    if opt.output is None:
        output = sys.stdout
    else:
        output = open(opt.output, 'w')
   
    main_reslist.write_cpin(output, opt.igb, opt.intdiel)
   
    if opt.output is not None:
        output.close()
   
    if solvated:
        if opt.outparm is None:
            has_carboxylate = False
            for res in main_reslist:
                if res is residues.AS4 or res is residues.GL4:
                    has_carboxylate = True
                    break
            if has_carboxylate:
                sys.stderr.write(
                        'Warning: Carboxylate residues in explicit solvent '
                        'simulations require a modified topology file!\n'
                        'Use the -op flag to print one.\n'
                )
        else:
            changeRadii(parm, 'mbondi2').execute()
            change(parm, 'RADII', ':AS4,GL4@OD=,OE=', 1.3).execute()
            parm.overwrite = True
            parm.writeParm(opt.outparm)
    else:
        if opt.outparm is not None:
            sys.stderr.write(
                    'A new prmtop is only necessary for explicit solvent '
                    'CpHMD/pH-REMD simulations.\n'
            )
コード例 #6
0
def prepare_prmtop(args, name):
    """ Places appropriate prmtop file into the calculation folder and scales
    it's charges if necessary.

    Parameters
    ----------

    args : Namespace
        Command line arguments

    Returns
    -------

    out : string
        Path to prmtop file.

    """
    # The atom specification in ParmedActions is terrible and requires the use
    # of masks. A good description of what it is can be found in Amber14 manual
    # section 28.2.3
    if args.file.endswith('.prmtop'):
        prmtop_name = args.file
    else:
        prmtop_name = generate_prmtop(name, args)
    if args.new_name:
        new_name = args.new_name
    else:
        new_name = prmtop_name
    if args.minimize:
        minimize_solute(name, prmtop_name, args)
    if args.nomod:
        # we are done
        return 0
    parm = AmberParm(prmtop_name)
    if args.charge_model == 'opls' or args.lennard_jones == 'opls':
        opls_radii, opls_epss, opls_chgs = get_opls_parameters(args, name)
    # account for scenario when charge_f is submitted along with existing prmtop
    if args.charge_f and args.file.endswith('.prmtop'):
        chargef_charges = get_chargef_charges(args.charge_f)
    #iterate over atoms
    for i, atom in enumerate(parm.atoms):
        attyp, atname, attchg = atom.type, atom.name, float(atom.charge)
        #print(attchg)
        nbidx = parm.LJ_types[attyp]
        lj_r = float(parm.LJ_radius[nbidx - 1])
        lj_eps = float(parm.LJ_depth[nbidx - 1])
        # change attyp to atnmae
        act = pact.change(parm,
                          '@{} AMBER_ATOM_TYPE {}'.format(atname, atname))
        act.execute()
        # deal with chgs
        if args.input_chg:
            print()
            attchg = get_usr_input('charge', atname, attchg)
        elif args.charge_model == 'opls':
            attchg = opls_chgs[i]
        elif args.charge_f and args.file.endswith('.prmtop'):
            attchg = float(chargef_charges[i])
        attchg = attchg * args.scale_chg
        act = pact.change(parm,
                          '@{} charge {:f}'.format(atname, float(attchg)))
        act.execute()
        # deal with lj
        if args.input_lj:
            if args.lj_radius_type == 'sigma':
                lj_r = lj_r * 2. / (2**(1. / 6))  # convert to sigma
            lj_r = get_usr_input('lj_r', atname, lj_r)
            if args.lj_radius_type == 'sigma':
                lj_r = lj_r / 2. * (2**(1. / 6))
            lj_eps = get_usr_input('lj_eps', atname, lj_eps)
        elif args.lennard_jones == 'opls':
            lj_r = opls_radii[i]
            lj_eps = opls_epss[i]
        lj_r = lj_r * args.scale_r
        lj_eps = lj_eps * args.scale_eps
        #print(lj_r, lj_eps)
        act = pact.changeLJSingleType(
            parm, '@{} {:f} {:f}'.format(atname, lj_r, lj_eps))
        act.execute()
    #parm.overwrite = True
    parm.write_parm(new_name)