Exemple #1
0
    def makeForceField(self, phys, *args):
        """
      Create a new MDL force field.

      @type phys: Physical
      @param phys: The physical system.

      @type args: tuple
      @param args: Python tuple, may have no values or a string \"charmm\"

      @rtype: ForceField
      @return: Newly instantiated MDL force field.
      """
        ff = ForceField()
        ff.charmm = 0
        ff.forceFactory = ForceFactory()
        if (args.__len__() > 0):
            ff.charmm = 1
        ff.theforces = self
        self.phys = ff.phys = phys
        ff.bc = phys.bc
        ff.setDefaults()
        self.energies.initialize(phys)
        ff.thisown = 0
        #self.myForceFields.append(ff)
        return ff
Exemple #2
0
   def makeForceField(self, phys, *args):
      """
      Create a new MDL force field.

      @type phys: Physical
      @param phys: The physical system.

      @type args: tuple
      @param args: Python tuple, may have no values or a string \"charmm\"

      @rtype: ForceField
      @return: Newly instantiated MDL force field.
      """
      ff = ForceField()
      ff.charmm = 0
      ff.forceFactory = ForceFactory()
      if (args.__len__() > 0):
         ff.charmm = 1
      ff.theforces = self
      self.phys = ff.phys = phys
      ff.bc = phys.bc
      ff.setDefaults()
      self.energies.initialize(phys)
      ff.thisown = 0
      #self.myForceFields.append(ff)
      return ff
Exemple #3
0
def run(infile):

    if os.path.isfile(infile) != 1:
        print("ERROR: setup file not found!")
        sys.exit(1)

    #parse input file
    params = Parser()
    params.set_default_values()
    params.parse(infile)  #parse input file
    params.check_variables()  #check consistency of defined variables

    #folder name equal path + system name
    folder = "%s/%s" % (params.output_folder, params.output)

    #if output folder does not exist, create it
    if os.path.isdir(folder) != 1:
        try:
            os.makedirs(folder)
        except:
            print("\n> could not create output folder %s!" % folder)
            return

    else:
        print(
            "\n> WARNING: found folder %s. Existing files will be overwritten..."
            % folder)

    #prepare logger
    logname = '%s/%s.log' % (folder, params.output)
    if os.path.isfile(logname):
        os.remove(logname)

    #@todo kill all previous handles and close logfiles before proceeding (in case an unexpected crash happened before)
    logger = logging.getLogger('assemble')
    logger.setLevel(logging.INFO)
    fh = logging.FileHandler(logname)
    ch = logging.StreamHandler()
    logger.addHandler(fh)
    logger.addHandler(ch)
    logger.info(">                 Assemble v1.0                     <")
    logger.info("> (c) 2014, Matteo Degiacomi and Valentina Erastova <")

    if params.mode == "gromacs":
        ff = ForceField()
        ff.load(params.ff)
        ff.default_bond = params.default_bond
        ff.default_angle = params.default_angle
        ff.default_dihedral = params.default_dihedral
    else:
        ff = ""

    #load molecules objects into hash table from database list
    db = Database()
    if params.db != "":
        try:
            db.load(params.db, params.mode)
        except Exception as e:
            logger.exception(e)
            fh.close()
            logger.removeHandler(fh)
            logger.removeHandler(ch)
            sys.exit(1)

    if len(params.residue.keys()) > 0:
        logger.info("\n> adding residues in database...")

    for r in params.residue.keys():
        try:
            if params.mode == "pdb":
                db.add(r, params.residue[r])
            if params.mode == "gromacs":
                db.add(r, params.residue[r][0], params.residue[r][1])
        except:
            logger.exception(e)
            fh.close()
            logger.removeHandler(fh)
            logger.removeHandler(ch)

    #create random chains for all the molecules not having a chain explicitly defined
    for m in params.molecule:
        if m not in params.chain:
            logger.info("\n> randomizing polymer chain for molecule %s..." % m)
            params.chain[m] = make_chain(params.length[m],
                                         params.percentage[m])

    polymers = []
    for m in params.molecule:

        try:

            #generate polymer
            poly = Polymer(db, ff, m, params.mode, params.gromacs_nrxl)
            poly.clash_thresh = params.clash_thresh
            poly.make(params.chain[m])

            if params.mode == "pdb":
                poly.write_polymer(typef="pdb", mypath=folder)
            elif params.mode == "gromacs":
                poly.write_polymer(typef="gromacs", mypath=folder)
                poly.write_gromacs(mypath=folder)

            polymers.append(poly)

        except Exception as e:
            logger.exception(e)
            fh.close()
            logger.removeHandler(fh)
            logger.removeHandler(ch)

    if np.any(params.box_grid_shape == 0):
        logger.warning(
            "\n> no box size information provided, skipping system generation..."
        )
        fh.close()
        logger.removeHandler(fh)
        logger.removeHandler(ch)
        return

    if params.mode == "gromacs":
        logger.info("\n> generating system...\n")
        system = System(polymers, ff, params)
        system.create_system(mypath=folder)

    logger.info("\n> All done! Thank you for using Assemble! <")
    fh.close()
    logger.removeHandler(fh)
    logger.removeHandler(ch)
Exemple #4
0
    def setUpMM3(input, mol, types):

        masses = mol.get_masses() * amu
        nAtoms = len(masses)
        topology = app.topology.Topology()
        f = ff.MM3(mol,types)

        chain = topology.addChain('Main')
        res = topology.addResidue('mm3', chain)
        atoms = []
        for a,t in zip(masses, f.types):
            elem = app.element.Element.getByMass(a)
            atoms.append(topology.addAtom(str('mm3_')+str(t),elem,res))

        # Create a system and add particles to it
        system = openmm.System()
        for index in range(nAtoms):
            # Particles are added one at a time
            # Their indices in the System will correspond with their indices in the Force objects we will add later
            system.addParticle(masses[index])



        # Add Lennard-Jones interactions using a NonbondedForce. Only required so that openMM can set up exclusions.
        force = openmm.NonbondedForce()
        force.setUseDispersionCorrection(False) # use long-range isotropic dispersion correction
        force.addParticle(0.5,1,4.184)

        # Add custom bond term
        bondForce = openmm.CustomBondForce("k*0.5*(r-r_eq)*(r-r_eq)*(1.0+cs*(r-r_eq) + (7.0/12.0)*cs*cs*(r-r_eq)*(r-r_eq))")
        bondForce.addPerBondParameter("k")#Force constant
        bondForce.addPerBondParameter("r_eq")#Equilibrium distance
        #cs converted from 1/A to 1/nm
        bondForce.addGlobalParameter("cs",-2.55 *10.0)
        # Add custom force to system
        system.addForce(bondForce)
        # Iterate through bond list
        bondPairs = []
        for bond in f.bondList:
            #Add bond term to forces. Fields 1 and 2 are the atom indicies and fields 3 and 4 are parameters k and r_eq
            bondForce.addBond(bond[0],bond[1], [bond[2]*602.3*AngstromsPerNm*AngstromsPerNm, bond[3]*NmPerAngstrom])
            bondPairs.append((bond[0],bond[1]))
            id1,id2 = bond[0],bond[1]
            topology.addBond(atoms[id1],atoms[id2])


        # Custom angle term
        angleForce = openmm.CustomAngleForce("k *0.5 *dtheta*dtheta*expansion;""expansion= 1.0 -0.014*dtor*dtheta+ 5.6e-5*dtor^2*dtheta^2-1.0e-6*dtor^3*dtheta^3+2.2e-8*dtor^4*dtheta^4;""dtor=57.295779;""dtheta = theta- theta_eq")
        angleForce.addPerAngleParameter("k")
        angleForce.addPerAngleParameter("theta_eq")
        system.addForce(angleForce)
        for angle in f.angleList:
            #Add bond term to forces. Fields 1, 2 and 3 are the atom indicies and fields 4 and 5 are parameters k and r_eq
            angleForce.addAngle(angle[0],angle[1],angle[2], [angle[3]*602.3,angle[4]*RadiansPerDegree])

        # Custom angle term
        # dihedralForce = openmm.CustomTorsionForce("0.5*V1*(1-cos(theta)) + 0.5*V2*(1-cos(2* (theta-3.141592)))+0.5*V3*(1-cos(3*theta))")
        # dihedralForce.addPerTorsionParameter("V1")
        # dihedralForce.addPerTorsionParameter("V2")
        # dihedralForce.addPerTorsionParameter("V3")
        # system.addForce(dihedralForce)
        # for dihedral in f.dihedralList:
        #     #Add bond term to forces. Fields 1, 2 and 3 are the atom indicies and fields 4 and 5 are parameters k and r_eq
        #     dihedralForce.addTorsion(dihedral[0],dihedral[1],dihedral[2],dihedral[3], [dihedral[4]*4.184,dihedral[5]*4.184,dihedral[6]*4.184])

        LJforce = openmm.CustomNonbondedForce("4.0*epsilon*(sigma^12/r^12 - sigma^6/r^6);"
																				 "sigma=((sig1+sig2)/2.0);"
																				 "epsilon=sqrt(eps1*eps2)")
        #Add any required parameters
        LJforce.addPerParticleParameter("sig")
        LJforce.addPerParticleParameter("eps")

        #Pass each particle params
        for LJ in f.LJList:
            LJforce.addParticle([LJ[0]*NmPerAngstrom,LJ[1]*4.184])

        #After we've defined the LJ, we need to tell OpenMM to skip calculation where a bond or angle exists between to the two particles
        num_exceptions = force.getNumExceptions()

        LJforce.setNonbondedMethod(openmm.CustomNonbondedForce.CutoffNonPeriodic)
        #Set cutoff distance in nm
        LJforce.setCutoffDistance(3.0*NmPerAngstrom)

        #Create exceptions for non-bonded interactions
        for b in bondPairs:
            force.addException(b[0], b[1], 1, 1.0/1.2, 1.0/2.0)
            LJforce.addExclusion(b[0],b[1])

        system.addForce(LJforce)

        #dihedralForce = openmm.CustomTorsionForce()
        #for index in range(nAtoms): # all particles must have parameters assigned for the NonbondedForce
            # Particles are assigned properties in the same order as they appear in the System object
        #    force4.addParticle(charge, sigma, epsilon)
        #force_index4 = system.addForce(force4)
        return system,topology
Exemple #5
0
def run(infile):
     
    if os.path.isfile(infile)!=1 :
        print "ERROR: setup file not found!"
        sys.exit(1)
    
    #parse input file
    params=Parser()
    params.set_default_values()
    params.parse(infile) #parse input file
    params.check_variables() #check consistency of defined variables
   
    #folder name equal path + system name
    folder="%s/%s"%(params.output_folder,params.output)

    #if output folder does not exist, create it
    if os.path.isdir(folder)!=1 :
        try:
            os.makedirs(folder)
        except:
            print "\n> could not create output folder %s!"%folder
            return

    else:
        print "\n> WARNING: found folder %s. Existing files will be overwritten..."%folder
   
    #prepare logger
    logname='%s/%s.log'%(folder,params.output)
    if os.path.isfile(logname):
        os.remove(logname)
    
    #@todo kill all previous handles and close logfiles before proceeding (in case an unexpected crash happened before)
    logger = logging.getLogger('assemble')
    logger.setLevel(logging.INFO)
    fh = logging.FileHandler(logname)
    ch = logging.StreamHandler()
    logger.addHandler(fh)
    logger.addHandler(ch)
    logger.info(">                 Assemble v1.0                     <")
    logger.info("> (c) 2014, Matteo Degiacomi and Valentina Erastova <")
    
    if params.mode=="gromacs":
        ff=ForceField()
        ff.load(params.ff)
        ff.default_bond=params.default_bond
        ff.default_angle=params.default_angle
        ff.default_dihedral=params.default_dihedral
    else:
        ff=""
    
    #load molecules objects into hash table from database list
    db=Database()
    if params.db!="":
        try:
            db.load(params.db,params.mode)
        except Exception, e:
            logger.exception(e)
            fh.close()
            logger.removeHandler(fh)
            logger.removeHandler(ch)
            sys.exit(1)
Exemple #6
0
def run(infile):

    if os.path.isfile(infile) != 1:
        print "ERROR: setup file not found!"
        sys.exit(1)

    #parse input file
    params = Parser()
    params.set_default_values()
    params.parse(infile)  #parse input file
    params.check_variables()  #check consistency of defined variables

    #folder name equal path + system name
    folder = "%s/%s" % (params.output_folder, params.output)

    #if output folder does not exist, create it
    if os.path.isdir(folder) != 1:
        try:
            os.makedirs(folder)
        except:
            print "\n> could not create output folder %s!" % folder
            return

    else:
        print "\n> WARNING: found folder %s. Existing files will be overwritten..." % folder

    #prepare logger
    logname = '%s/%s.log' % (folder, params.output)
    if os.path.isfile(logname):
        os.remove(logname)

    #@todo kill all previous handles and close logfiles before proceeding (in case an unexpected crash happened before)
    logger = logging.getLogger('assemble')
    logger.setLevel(logging.INFO)
    fh = logging.FileHandler(logname)
    ch = logging.StreamHandler()
    logger.addHandler(fh)
    logger.addHandler(ch)
    logger.info(">                 Assemble v1.0                     <")
    logger.info("> (c) 2014, Matteo Degiacomi and Valentina Erastova <")

    if params.mode == "gromacs":
        ff = ForceField()
        ff.load(params.ff)
        ff.default_bond = params.default_bond
        ff.default_angle = params.default_angle
        ff.default_dihedral = params.default_dihedral
    else:
        ff = ""

    #load molecules objects into hash table from database list
    db = Database()
    if params.db != "":
        try:
            db.load(params.db, params.mode)
        except Exception, e:
            logger.exception(e)
            fh.close()
            logger.removeHandler(fh)
            logger.removeHandler(ch)
            sys.exit(1)