Example #1
0
""" % (extras, prev_str, resname, next_str, resname.lower(), resname.lower())

   if igb == 1:
      tleap_script = tleap_script % 'mbondi'
   elif igb == 7:
      tleap_script = tleap_script % 'bondi'
   elif igb == 8:
      tleap_script = tleap_script % 'mbondi3'
   else:
      tleap_script = tleap_script % 'mbondi2'

open("tleap.in","w").write(tleap_script)
os.system(tleap + " -f tleap.in > tleap.log")

prm = AmberParm("%s0.prmtop" % resname.lower())
prm.overwrite = True # allow the prmtop to be overwritten

# check validity of prmtop

if not prm.valid:
   sys.exit('Error: Invalid prmtop (%s)!' % prm)

if isolated or not prev_str:
   act = changeprotstate(prm, ':1 %s' % opt.state0)
else:
   act = changeprotstate(prm, ':2 %s' % opt.state0)
act.execute()
prm.writeParm(str(prm))
chg1 = netcharge(prm, '*').execute()

if isolated or not prev_str:
Example #2
0
def main(opt):
   # Check all of the arguments
   if not os.path.exists(opt.prmtop):
      raise CpinInputError('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 CpinInputError('-igb must be 2, 5, or 8!')
   
   if resnums is not None and notresnums is not None:
      raise CpinInputError('Cannot specify -resnums and -notresnums together')
   
   if resnames is not None and notresnames is not None:
      raise CpinInputError('Cannot specify -resnames and -notresnames together')
   
   if opt.intdiel != 1 and opt.intdiel != 2:
      raise CpinInputError('-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 CpinInputError('%s is not a titratable residue!' % resname)
         titratable_residues.append(resname)
   else:
      titratable_residues = residues.titratable_residues[:]
   print str(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 CpinInputError('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 CpinInputError('%s only has %d residues. (%d chosen)' % (parm,
                                 parm.ptr('nres'), resnum))
         if resnum <= 0:
            raise CpinInputError('Cannot select negative residue numbers.')
         resname = parm.parm_data['RESIDUE_LABEL'][resnum-1]
         if not resname in titratable_residues:
            raise CpinInputError('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:
          print resname
          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')-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', 0)
   
   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:
            print >> sys.stderr, "Warning: Carboxylate residues in explicit ",
            print >> sys.stderr, "solvent simulations require a modified"
            print >> sys.stderr, "topology file! Use the -op flag to print one."
      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:
         print >> sys.stderr, "A new prmtop is only necessary for explicit ",
         print >> sys.stderr, "solvent CpHMD simulations."

   sys.stderr.write('CPIN generation complete!\n')
Example #3
0
def main(opt):
    # Check all of the arguments
    if not os.path.exists(opt.prmtop):
        raise CpinInputError('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 CpinInputError('-igb must be 2, 5, or 8!')

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

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

    if opt.intdiel != 1 and opt.intdiel != 2:
        raise CpinInputError('-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 CpinInputError('%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 CpinInputError('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 CpinInputError('%s only has %d residues. (%d chosen)' %
                                     (parm, parm.ptr('nres'), resnum))
            if resnum <= 0:
                raise CpinInputError('Cannot select negative residue numbers.')
            resname = parm.parm_data['RESIDUE_LABEL'][resnum - 1]
            if not resname in titratable_residues:
                raise CpinInputError(
                    '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') - 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', 0)

    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:
                print >> sys.stderr, "Warning: Carboxylate residues in explicit ",
                print >> sys.stderr, "solvent simulations require a modified"
                print >> sys.stderr, "topology file! Use the -op flag to print one."
        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:
            print >> sys.stderr, "A new prmtop is only necessary for explicit ",
            print >> sys.stderr, "solvent CpHMD simulations."

    sys.stderr.write('CPIN generation complete!\n')