Exemple #1
0
def loadQMMMSystem():
    """This function is called to set up the system. It sets everything
       up, then returns a System object that holds the configured system"""

    print("Loading the system...")

    t = QTime()

    if os.path.exists(s3file.val):
        print("Loading existing s3 file %s..." % s3file.val)
        loadsys = Sire.Stream.load(s3file.val)

    else:
        print("Loading from Amber files %s / %s..." % (topfile.val, crdfile.val))
        # Add the name of the ligand to the list of solute molecules
        sys_scheme = NamingScheme()
        sys_scheme.addSoluteResidueName(ligand_name.val)

        # Load up the system. This will automatically find the protein, solute, water, solvent
        # and ion molecules and assign them to different groups
        loadsys = createSystem(topfile.val, crdfile.val, sys_scheme)
        ligand_mol = findMolecule(loadsys, ligand_name.val)

        if ligand_mol is None:
            print("Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val)
            sys.exit(-1)

        # Center the system with the ligand at (0,0,0)
        loadsys = centerSystem(loadsys, ligand_mol)
        ligand_mol = loadsys[ligand_mol.number()].molecule()

        if reflection_radius.val is None:
            loadsys = addFlexibility(loadsys, naming_scheme=sys_scheme )
        else:
            loadsys = addFlexibility(loadsys, Vector(0), reflection_radius.val, naming_scheme=sys_scheme)

        Sire.Stream.save(loadsys, s3file.val)

    ligand_mol = findMolecule(loadsys, ligand_name.val)

    if ligand_mol is None:
        print("Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val)
        sys.exit(-1)

    # Now build the QM/MM system
    system = System("QMMM system")

    if loadsys.containsProperty("reflection center"):
        reflect_center = loadsys.property("reflection center").toVector()[0]
        reflect_radius = float(str(loadsys.property("reflection sphere radius")))

        system.setProperty("reflection center", AtomCoords(CoordGroup(1,reflect_center)))
        system.setProperty("reflection sphere radius", VariantProperty(reflect_radius))
        space = Cartesian()
    else:
        space = loadsys.property("space")

    if loadsys.containsProperty("average solute translation delta"):
        system.setProperty("average solute translation delta", \
                           loadsys.property("average solute translation delta"))

    if loadsys.containsProperty("average solute rotation delta"):
        system.setProperty("average solute rotation delta", \
                           loadsys.property("average solute rotation delta"))

    # create a molecule group to hold all molecules
    all_group = MoleculeGroup("all")

    # create a molecule group for the ligand
    ligand_group = MoleculeGroup("ligand")
    ligand_group.add(ligand_mol)
    all_group.add(ligand_mol)

    groups = []
    groups.append(ligand_group)

    # pull out the groups that we want from the two systems

    # create a group to hold all of the fixed molecules in the bound leg
    fixed_group = MoleculeGroup("fixed_molecules")
    if MGName("fixed_molecules") in loadsys.mgNames():
        fixed_group.add( loadsys[ MGName("fixed_molecules") ] )

    if save_pdb.val:
        # write a PDB of the fixed atoms in the bound and free legs
        if not os.path.exists(outdir.val):
            os.makedirs(outdir.val)

        PDB().write(fixed_group, "%s/fixed.pdb" % outdir.val)

    # create a group to hold all of the mobile solute molecules
    mobile_solutes_group = MoleculeGroup("mobile_solutes")
    if MGName("mobile_solutes") in loadsys.mgNames():
        mobile_solutes_group.add( loadsys[MGName("mobile_solutes")] )
        mobile_solutes_group.remove(ligand_mol)
        if mobile_solutes_group.nMolecules() > 0:
            all_group.add(mobile_solutes_group)
    
    groups.append(mobile_solutes_group)

    # create a group to hold all of the mobile solvent molecules
    mobile_solvents_group = MoleculeGroup("mobile_solvents")
    if MGName("mobile_solvents") in loadsys.mgNames():
        mols = loadsys[MGName("mobile_solvents")]
        for molnum in mols.molNums():
            solvent_mol = mols[molnum].molecule()
            mobile_solvents_group.add(solvent_mol)

        all_group.add(mobile_solvents_group)

        print("The number of mobile solvent molecules is %d." % mobile_solvents_group.nMolecules())

    groups.append(mobile_solvents_group)

    # create the groups to hold all of the protein molecules. We will use "extract" to 
    # pull out only those protein atoms that are in the mobile region
    protein_intra_group = MoleculeGroup("protein_intra_group")
    mobile_proteins_group = MoleculeGroup("proteins")
    mobile_protein_sidechains_group = MoleculeGroup("mobile_sidechains")
    mobile_protein_backbones_group = MoleculeGroup("mobile_backbones")

    if MGName("protein_sidechains") in loadsys.mgNames() or \
       MGName("protein_backbones") in loadsys.mgNames():

        all_proteins = Molecules()

        try:
            protein_sidechains = loadsys[MGName("protein_sidechains")]
            all_proteins.add(protein_sidechains.molecules())
        except:
            protein_sidechains = MoleculeGroup()

        try:
            protein_backbones = loadsys[MGName("protein_backbones")]
            all_proteins.add(protein_backbones.molecules())
        except:
            protein_backbones = MoleculeGroup()

        try:
            boundary_molecules = loadsys[MGName("boundary_molecules")]
            all_proteins.add(boundary_molecules.molecules())
        except:
            boundary_molecules = MoleculeGroup()

        for molnum in all_proteins.molNums():
            protein_mol = all_proteins[molnum].join()
            
            if protein_mol.selectedAll():
                protein_intra_group.add(protein_mol)
                all_group.add(protein_mol)

                mobile_protein = None                

                try:
                    mobile_protein = protein_sidechains[molnum]
                    mobile_protein_sidechains_group.add( mobile_protein )
                except:
                    pass

                try:
                    if mobile_protein is None:
                        mobile_protein = protein_backbones[molnum]
                        mobile_protein_backbones_group.add( mobile_protein )
                    else:
                        mobile_protein.add( protein_backbones[molnum].selection() )
                        mobile_protein_backbones_group.add( protein_backbones[molnum] )
                except:
                    pass

                if not (mobile_protein is None):
                    mobile_proteins_group.add( mobile_protein.join() )

            else:
                # only some of the atoms have been selected. We will extract
                # the mobile atoms and will then update all of the other selections
                print("Extracting the mobile atoms of protein %s" % protein_mol)
                new_protein_mol = protein_mol.extract()
                print("Extracted %d mobile atoms from %d total atoms..." % \
                                        (new_protein_mol.nAtoms(), protein_mol.molecule().nAtoms()))

                protein_intra_group.add(new_protein_mol)
                all_group.add( new_protein_mol )

                mobile_protein_view = new_protein_mol.selection()
                mobile_protein_view = mobile_protein_view.selectNone()

                try:
                    sidechains = protein_sidechains[molnum]

                    for i in range(0,sidechains.nViews()):
                        view = new_protein_mol.selection()
                        view = view.selectNone()

                        for atomid in sidechains.viewAt(i).selectedAtoms():
                            atom = protein_mol.atom(atomid)
                            resatomid = ResAtomID( atom.residue().number(), atom.name() )
                            view = view.select( resatomid )
                            mobile_protein_view = mobile_protein_view.select( resatomid )

                        if view.nSelected() > 0:
                            mobile_protein_sidechains_group.add( PartialMolecule(new_protein_mol, view) )
                except:
                    pass

                try:
                    backbones = protein_backbones[molnum]

                    for i in range(0,backbones.nViews()):
                        view = new_protein_mol.selection()
                        view = view.selectNone()

                        for atomid in backbones.viewAt(i).selectedAtoms():
                            atom = protein_mol.atom(atomid)
                            resatomid = ResAtomID( atom.residue().number(), atom.name() )
                            view = view.select( resatomid )
                            mobile_protein_view = mobile_protein_view.select( resatomid )

                        if view.nSelected() > 0:
                            mobile_protein_backbones_group.add( PartialMolecule(new_protein_mol, view) )
                except:
                    pass

                if mobile_protein_view.nSelected() > 0:
                    mobile_proteins_group.add( PartialMolecule(new_protein_mol, mobile_protein_view) )

    groups.append(mobile_protein_backbones_group)
    groups.append(mobile_protein_sidechains_group)
    groups.append(all_group)

    # finished added in all of the proteins
    for group in groups:
        if group.nMolecules() > 0:
            print("Adding group %s" % group.name())
            system.add(group)

    # now add in the forcefields for the system...
    print("Creating the forcefields for the QM/MM system...")

    # first, group together the molecules grouped above into convenient
    # groups for the forcefields

    # group holding just the ligand
    ligand_mols = ligand_group.molecules()

    # group holding all of the mobile atoms
    mobile_mols = mobile_solvents_group.molecules()
    mobile_mols.add( mobile_solutes_group.molecules() )
    mobile_mols.add( protein_intra_group.molecules() )

    # group holding all of the mobile atoms in the bound leg, excluding the 
    # buffer atoms that are fixed, but bonded to mobile atoms
    mobile_buffered_mols = mobile_solvents_group.molecules()
    mobile_buffered_mols.add( mobile_solutes_group.molecules() )
    mobile_buffered_mols.add( mobile_proteins_group.molecules() )

    # group holding all of the protein molecules that need intramolecular terms calculated
    protein_intra_mols = protein_intra_group.molecules()

    # group holding all of the solute molecules that nede intramolecular terms calculated
    solute_intra_mols = mobile_solutes_group.molecules()

    forcefields = []

    ###
    ### INTRA-ENERGY OF THE LIGAND AND CLUSTER
    ###
    
    # intramolecular energy of the ligand
    ligand_intraclj = IntraCLJFF("ligand:intraclj")
    ligand_intraclj = setCLJProperties(ligand_intraclj, space)
    ligand_intraclj.add(ligand_mols)

    ligand_intraff = InternalFF("ligand:intra")
    ligand_intraff.add(ligand_mols)

    forcefields.append(ligand_intraclj)
    forcefields.append(ligand_intraff)

    ligand_mm_nrg = ligand_intraclj.components().total() + ligand_intraff.components().total()

    ###
    ### FORCEFIELDS INVOLVING THE LIGAND/CLUSTER AND OTHER ATOMS
    ###

    # forcefield holding the energy between the ligand and the mobile atoms in the
    # bound leg
    ligand_mobile = InterGroupCLJFF("system:ligand-mobile")
    ligand_mobile = setCLJProperties(ligand_mobile, space)

    ligand_mobile.add(ligand_mols, MGIdx(0))
    ligand_mobile.add(mobile_mols, MGIdx(1))

    qm_ligand = QMMMFF("system:ligand-QM")    
    qm_ligand = setQMProperties(qm_ligand, space)

    qm_ligand.add(ligand_mols, MGIdx(0))

    zero_energy = 0

    if not intermolecular_only.val:
        if qm_zero_energy.val is None:
            # calculate the delta value for the system - this is the difference between
            # the MM and QM intramolecular energy of the ligand
            t.start()
            print("\nComparing the MM and QM energies of the ligand...")
            mm_intra = ligand_intraclj.energy().value() + ligand_intraff.energy().value()
            print("MM energy = %s kcal mol-1 (took %s ms)" % (mm_intra, t.elapsed()))

            t.start()
            qm_intra = qm_ligand.energy().value()
            print("QM energy = %s kcal mol-1 (took %s ms)" % (qm_intra, t.elapsed()))

            print("\nSetting the QM zero energy to %s kcal mol-1" % (qm_intra - mm_intra))
            qm_ligand.setZeroEnergy( (qm_intra-mm_intra) * kcal_per_mol )
            zero_energy = qm_intra - mm_intra
        else:
            print("\nManually setting the QM zero energy to %s" % qm_zero_energy.val)
            qm_ligand.setZeroEnergy( qm_zero_energy.val )
            zero_energy = qm_zero_energy.val

    qm_ligand.add(mobile_mols, MGIdx(1))

    ligand_mm_nrg += ligand_mobile.components().total()
    ligand_qm_nrg = qm_ligand.components().total() + ligand_mobile.components().lj()

    if intermolecular_only.val:
        # the QM model still uses the MM intramolecular energy of the ligand
        ligand_qm_nrg += ligand_intraclj.components().total() + ligand_intraff.components().total()

    forcefields.append(ligand_mobile)
    forcefields.append(qm_ligand)

    if fixed_group.nMolecules() > 0:
        # there are fixed molecules

        # Whether or not to disable the grid and calculate all energies atomisticly
        if disable_grid:
            # we need to renumber all of the fixed molecules so that they don't clash
            # with the mobile molecules
            print("Renumbering fixed molecules...")
            fixed_group = renumberMolecules(fixed_group)

        # forcefield holding the energy between the ligand and the fixed atoms in the bound leg
        if disable_grid:
            ligand_fixed = InterGroupCLJFF("system:ligand-fixed")
            ligand_fixed = setCLJProperties(ligand_fixed, space)
            ligand_fixed = setFakeGridProperties(ligand_fixed, space)

            ligand_fixed.add(ligand_mols, MGIdx(0))
            ligand_fixed.add(fixed_group, MGIdx(1))

            qm_ligand.add(fixed_group, MGIdx(1))

            ligand_mm_nrg += ligand_fixed.components().total()
            ligand_qm_nrg += ligand_fixed.components().lj()

            forcefields.append(ligand_fixed)

        else:
            ligand_fixed = GridFF("system:ligand-fixed")
            ligand_fixed = setCLJProperties(ligand_fixed, space)
            ligand_fixed = setGridProperties(ligand_fixed)

            ligand_fixed.add(ligand_mols, MGIdx(0))
            ligand_fixed.addFixedAtoms( fixed_group )

            qm_ligand.addFixedAtoms( fixed_group )

            ligand_mm_nrg += ligand_fixed.components().total()
            ligand_qm_nrg += ligand_fixed.components().lj()

            forcefields.append(ligand_fixed)

    ###
    ### FORCEFIELDS NOT INVOLVING THE LIGAND
    ###

    # forcefield holding the intermolecular energy between all molecules
    mobile_mobile = InterCLJFF("mobile-mobile")
    mobile_mobile = setCLJProperties(mobile_mobile, space)

    mobile_mobile.add(mobile_mols)

    other_nrg = mobile_mobile.components().total()
    forcefields.append(mobile_mobile)

    # forcefield holding the energy between the mobile atoms and  
    # the fixed atoms
    if disable_grid.val:
        mobile_fixed = InterGroupCLJFF("mobile-fixed")
        mobile_fixed = setCLJProperties(mobile_fixed)
        mobile_fixed = setFakeGridProperties(mobile_fixed, space)
        mobile_fixed.add(mobile_buffered_mols, MGIdx(0))
        mobile_fixed.add(fixed_group, MGIdx(1))
        other_nrg += mobile_fixed.components().total()
        forcefields.append(mobile_fixed)
    else:
        mobile_fixed = GridFF("mobile-fixed")
        mobile_fixed = setCLJProperties(mobile_fixed, space)
        mobile_fixed = setGridProperties(mobile_fixed)

        # we use mobile_buffered_group as this group misses out atoms that are bonded
        # to fixed atoms (thus preventing large energies caused by incorrect non-bonded calculations)
        mobile_fixed.add(mobile_buffered_mols, MGIdx(0))
        mobile_fixed.addFixedAtoms(fixed_group)
        other_nrg += mobile_fixed.components().total()
        forcefields.append(mobile_fixed)

    # intramolecular energy of the protein
    if protein_intra_mols.nMolecules() > 0:
        protein_intraclj = IntraCLJFF("protein_intraclj")
        protein_intraclj = setCLJProperties(protein_intraclj, space)

        protein_intraff = InternalFF("protein_intra")

        for molnum in protein_intra_mols.molNums():
            protein_mol = protein_intra_mols[molnum].join()
            protein_intraclj.add(protein_mol)
            protein_intraff.add(protein_mol)

        other_nrg += protein_intraclj.components().total()
        other_nrg += protein_intraff.components().total()
        forcefields.append(protein_intraclj)
        forcefields.append(protein_intraff)

    # intramolecular energy of any other solutes
    if solute_intra_mols.nMolecules() > 0:
        solute_intraclj = IntraCLJFF("solute_intraclj")
        solute_intraclj = setCLJProperties(solute_intraclj, space)

        solute_intraff = InternalFF("solute_intra")

        for molnum in solute_intra_mols.molNums():
            solute_mol = solute_intra_mols[molnum].join()
            solute_intraclj.add(solute_mol)
            solute_intraff.add(solute_mol)

        other_nrg += solute_intraclj.components().total()
        other_nrg += solute_intraff.components().total()
        forcefields.append(solute_intraclj)
        forcefields.append(solute_intraff)

    ###
    ### NOW ADD THE FORCEFIELDS TO THE SYSTEM
    ###
    ###
    ### SETTING THE FORCEFIELD EXPRESSIONS
    ###

    lam = Symbol("lambda")

    e_slow = ((1-lam) * ligand_qm_nrg) + (lam * ligand_mm_nrg) + other_nrg
    e_fast = ligand_mm_nrg + other_nrg

    de_by_dlam = ligand_mm_nrg - ligand_qm_nrg

    for forcefield in forcefields:
        system.add(forcefield)

    system.setConstant(lam, 0.0)

    system.setComponent(Symbol("E_{fast}"), e_fast)
    system.setComponent(Symbol("E_{slow}"), e_slow)
    system.setComponent(Symbol("dE/dlam"), de_by_dlam)
    system.setComponent( system.totalComponent(), e_slow )
 
    system.setProperty("space", space)
    
    if space.isPeriodic():
        # ensure that all molecules are wrapped into the space with the ligand at the center
        print("Adding in a space wrapper constraint %s, %s" % (space, ligand_mol.evaluate().center()))
        system.add( SpaceWrapper( ligand_mol.evaluate().center(), all_group ) )
        system.applyConstraints()

    print("\nHere are the values of all of the initial energy components...")
    t.start()
    printEnergies(system.energies())
    print("(these took %d ms to evaluate)\n" % t.elapsed())

    # Create a monitor to monitor the free energy average
    system.add( "dG/dlam", MonitorComponent(Symbol("dE/dlam"), AverageAndStddev()) )

    if intermolecular_only.val:
        print("\n\n## This simulation uses QM to model *only* the intermolecular energy between")
        print("## the QM and MM atoms. The intramolecular energy of the QM atoms is still")
        print("## modelled using MM.\n")
    else:
        print("\n\n## This simulation uses QM to model both the intermolecular and intramolecular")
        print("## energies of the QM atoms. Because the this, we have to adjust the 'zero' point")
        print("## of the QM potential. You need to add the value %s kcal mol-1 back onto the" % zero_energy)
        print("## QM->MM free energy calculated using this program.\n")

    return system
def _pvt_calculateEnergy(lamval, verbose):
    cljff01 = InterGroupCLJFF("cljff01")
    cljff02 = InterGroupCLJFF("cljff02")

    cljff01.add( water0, MGIdx(0) )
    cljff01.add( water1, MGIdx(1) )

    cljff02.add( water0, MGIdx(0) )
    cljff02.add( water2, MGIdx(1) )

    soft_cljff01 = InterGroupSoftCLJFF("soft_cljff01")
    soft_cljff02 = InterGroupSoftCLJFF("soft_cljff02")

    soft_cljff01.add( water0, MGIdx(0) )
    soft_cljff01.add( water1, MGIdx(1) )

    soft_cljff02.add( water0, MGIdx(0) )
    soft_cljff02.add( water2, MGIdx(1) )

    ref = MoleculeGroup("ref", water0)
    group_a = MoleculeGroup("group_a", water1)
    group_b = MoleculeGroup("group_b", water2)

    dlam = 0.001
    lamval_f = lamval + dlam

    lam = Symbol("lambda")
    lam_f = Symbol("lambda_f")

    soft_nrg = (1-lam) * soft_cljff01.components().total(0) + lam * soft_cljff02.components().total(0)
    soft_nrg_f = (1-lam_f) * soft_cljff01.components().total(1) + lam_f * soft_cljff02.components().total(1)

    de_soft = soft_nrg_f - soft_nrg

    nrg = ((1-lam) * cljff01.components().total()) + (lam * cljff02.components().total())
    nrg_f = ((1-lam_f) * cljff01.components().total()) + (lam_f * cljff02.components().total())

    de = nrg_f - nrg

    soft_cljff01.setProperty("alpha0", VariantProperty(lamval))
    soft_cljff02.setProperty("alpha0", VariantProperty(1-lamval))
    soft_cljff01.setProperty("alpha1", VariantProperty(lamval_f))
    soft_cljff02.setProperty("alpha1", VariantProperty(1-lamval_f))

    soft_cljff01.setProperty("coulombPower", VariantProperty(0))
    soft_cljff01.setProperty("shiftDelta", VariantProperty(1.1))
    soft_cljff02.setProperty("coulombPower", VariantProperty(0))
    soft_cljff02.setProperty("shiftDelta", VariantProperty(1.1))

    sys = System()
    sys.add(cljff01)
    sys.add(cljff02)
    sys.add(soft_cljff01)
    sys.add(soft_cljff02)
    sys.add(ref)
    sys.add(group_a)
    sys.add(group_b)
    sys.setComponent(lam, lamval)
    sys.setComponent(lam_f, lamval_f)
    sys.setComponent(sys.totalComponent(), nrg)
    sys.setComponent(Symbol("E_{total_f}"), nrg_f)
    sys.setComponent(Symbol("dE"), de)
    sys.setComponent(Symbol("E_soft_{total}"), soft_nrg)
    sys.setComponent(Symbol("E_soft_{total_f}"), soft_nrg_f)
    sys.setComponent(Symbol("dE_soft"), de_soft)

    nrgmon = FreeEnergyMonitor(ref, group_a, group_b)

    soft_nrgmon = FreeEnergyMonitor(ref, group_a, group_b)
    soft_nrgmon.setCoulombPower(0)
    soft_nrgmon.setShiftDelta(1.1)

    sys.add( "nrgmon", nrgmon )
    sys.add( "soft_nrgmon", soft_nrgmon)

    sys.collectStats()

    nrgmon = sys[ MonitorName("nrgmon") ]
    dg = nrgmon.freeEnergies()[0].average()

    soft_nrgmon = sys[ MonitorName("soft_nrgmon") ]
    soft_dg = soft_nrgmon.freeEnergies()[0].average()

    sys_dg = sys.energy(Symbol("dE")).value()
    sys_soft_dg = sys.energy(Symbol("dE_soft")).value()

    if verbose:
        print("%s : %s versus %s (should be equal)" % (lamval,dg,sys_dg))
        print("%s : %s versus %s (should be equal)" % (lamval,soft_dg,sys_soft_dg))

    assert_almost_equal(dg, sys_dg, 5)
    assert_almost_equal(soft_dg, sys_soft_dg, 5)
Exemple #3
0
# Sire performs simulations on simulation System objects.
# A System groups together all of the molecules, forcefields etc.
# into a single unit
system = System()
system.add(cljff)

# Here we create the equation used to calculate the total energy of the
# system. We define a symbol, lambda, which we use here to scale up and
# down the coulomb component of cljff
lam = Symbol("lambda")
total_nrg = cljff.components().lj() + lam * cljff.components().coulomb()

# Here we tell the system to use our equation to calculate the total
# energy, and we set the value of lambda to 0.5
system.setComponent( system.totalComponent(), total_nrg )
system.setConstant( lam, 0.5 )

# Now we create a MoleculeGroup that groups together all of the 
# molecules to be moved
mobile_mols = MoleculeGroup("mobile_molecules")
mobile_mols.add(first_water)
mobile_mols.add(second_water)

# We add the molecule group to the system
system.add(mobile_mols)

# We create a periodic boundaries space, and give it to the system
space = PeriodicBox( Vector(5,5,5) )
system.setProperty( "space", space )
Exemple #4
0
print("Initial energy = %s" % system.energy())

data = save(system)

system = load(data)

print("Saved energy = %s" % system.energy())

mc = RigidBodyMC(cljff.group(MGIdx(0)))

moves = SameMoves(mc)

#give a lambda coordinate that turns off the coulomb energy
lam = Symbol("lambda")

system.setComponent( system.totalComponent(), cljff.components().lj() + \
                                              lam * cljff.components().coulomb() )

system.setComponent(lam, 0.0)
print(system.energies())

system.setComponent(lam, 1.0)
print(system.energies())

#create 5 replicas that map from lambda=0 to lambda=1
replicas = Replicas(system, 5)
replicas.setSubMoves(moves)
replicas.setNSubMoves(1000)

replicas.setLambdaComponent(lam)

for i in range(0, 5):
Exemple #5
0
print("Initial energy = %s" % system.energy())

data = save(system)

system = load(data)

print("Saved energy = %s" % system.energy())

mc = RigidBodyMC(cljff.group(MGIdx(0)))

moves = SameMoves(mc)

#give a lambda coordinate that turns off the coulomb energy
lam = Symbol("lambda")

system.setComponent( system.totalComponent(), cljff.components().lj() + \
                                              lam * cljff.components().coulomb() )

system.setComponent( lam, 0.0 )
print(system.energies())

system.setComponent( lam, 1.0 )
print(system.energies())

#create 5 replicas that map from lambda=0 to lambda=1
replicas = Replicas(system, 5)
replicas.setSubMoves(moves)
replicas.setNSubMoves(1000)

replicas.setLambdaComponent(lam)

for i in range(0, 5):
Exemple #6
0
def createSystem():
    protomsdir = "%s/Work/ProtoMS" % os.getenv("HOME")

    protoms = ProtoMS("%s/protoms2" % protomsdir)

    protoms.addParameterFile("%s/parameter/amber99.ff" % protomsdir)
    protoms.addParameterFile("%s/parameter/solvents.ff" % protomsdir)
    protoms.addParameterFile("%s/parameter/gaff.ff" % protomsdir)
    protoms.addParameterFile(solute_params)

    solute = PDB().readMolecule(solute_file)
    solute = solute.edit().rename(solute_name).commit()
    solute = protoms.parameterise(solute, ProtoMS.SOLUTE)

    perturbation = solute.property("perturbations")

    lam = Symbol("lambda")
    lam_fwd = Symbol("lambda_{fwd}")
    lam_bwd = Symbol("lambda_{bwd}")

    initial = Perturbation.symbols().initial()
    final = Perturbation.symbols().final()

    solute = solute.edit().setProperty(
        "perturbations",
        perturbation.recreate((1 - lam) * initial + lam * final)).commit()

    solute_fwd = solute.edit().renumber().setProperty(
        "perturbations", perturbation.substitute(lam, lam_fwd)).commit()
    solute_bwd = solute.edit().renumber().setProperty(
        "perturbations", perturbation.substitute(lam, lam_bwd)).commit()

    solvent = PDB().read(solvent_file)

    tip4p = solvent.moleculeAt(0).molecule()
    tip4p = tip4p.edit().rename(solvent_name).commit()
    tip4p = protoms.parameterise(tip4p, ProtoMS.SOLVENT)

    tip4p_chgs = tip4p.property("charge")
    tip4p_ljs = tip4p.property("LJ")

    for i in range(0, solvent.nMolecules()):
        tip4p = solvent.moleculeAt(i).molecule()
        tip4p = tip4p.edit().rename(solvent_name) \
                            .setProperty("charge", tip4p_chgs) \
                            .setProperty("LJ", tip4p_ljs) \
                            .commit()

        solvent.update(tip4p)

    system = System()

    solutes = MoleculeGroup("solutes")
    solutes.add(solute)
    solutes.add(solute_fwd)
    solutes.add(solute_bwd)

    solvent = MoleculeGroup("solvent", solvent)

    all = MoleculeGroup("all")
    all.add(solutes)
    all.add(solvent)

    system.add(solutes)
    system.add(solvent)
    system.add(all)

    solventff = InterCLJFF("solvent:solvent")
    solventff.add(solvent)

    solute_intraff = InternalFF("solute_intraff")
    solute_intraff.add(solute)

    solute_fwd_intraff = InternalFF("solute_fwd_intraff")
    solute_fwd_intraff.add(solute_fwd)

    solute_bwd_intraff = InternalFF("solute_bwd_intraff")
    solute_bwd_intraff.add(solute_bwd)

    solute_intraclj = IntraCLJFF("solute_intraclj")
    solute_intraclj.add(solute)

    solute_fwd_intraclj = IntraCLJFF("solute_fwd_intraclj")
    solute_fwd_intraclj.add(solute_fwd)

    solute_bwd_intraclj = IntraCLJFF("solute_bwd_intraclj")
    solute_bwd_intraclj.add(solute_bwd)

    solute_solventff = InterGroupCLJFF("solute:solvent")
    solute_solventff.add(solute, MGIdx(0))
    solute_solventff.add(solvent, MGIdx(1))

    solute_fwd_solventff = InterGroupCLJFF("solute_fwd:solvent")
    solute_fwd_solventff.add(solute_fwd, MGIdx(0))
    solute_fwd_solventff.add(solvent, MGIdx(1))

    solute_bwd_solventff = InterGroupCLJFF("solute_bwd:solvent")
    solute_bwd_solventff.add(solute_bwd, MGIdx(0))
    solute_bwd_solventff.add(solvent, MGIdx(1))

    forcefields = [
        solventff, solute_intraff, solute_intraclj, solute_solventff,
        solute_fwd_intraff, solute_fwd_intraclj, solute_fwd_solventff,
        solute_bwd_intraff, solute_bwd_intraclj, solute_bwd_solventff
    ]

    for forcefield in forcefields:
        system.add(forcefield)

    xsc_line = open(solvent_file, "r").readlines()[0]
    words = xsc_line.split()

    #HEADER box  -12.5  -12.5  -12.5   12.5   12.5   12.5
    space = PeriodicBox(
        Vector(float(words[2]), float(words[3]), float(words[4])),
        Vector(float(words[5]), float(words[6]), float(words[7])))

    system.setProperty("space", space)
    system.setProperty(
        "switchingFunction",
        HarmonicSwitchingFunction(coulomb_cutoff, coulomb_feather, lj_cutoff,
                                  lj_feather))
    system.setProperty("combiningRules", VariantProperty(combining_rules))

    e_total = system.totalComponent()
    e_fwd = Symbol("E_{fwd}")
    e_bwd = Symbol("E_{bwd}")

    total_nrg = solventff.components().total() + \
                solute_intraclj.components().total() + solute_intraff.components().total() + \
                solute_solventff.components().total()

    fwd_nrg = solventff.components().total() + \
              solute_fwd_intraclj.components().total() + solute_fwd_intraff.components().total() + \
              solute_fwd_solventff.components().total()

    bwd_nrg = solventff.components().total() + \
              solute_bwd_intraclj.components().total() + solute_bwd_intraff.components().total() + \
              solute_bwd_solventff.components().total()

    system.setComponent(e_total, total_nrg)
    system.setComponent(e_fwd, fwd_nrg)
    system.setComponent(e_bwd, bwd_nrg)

    system.setConstant(lam, 0.0)
    system.setConstant(lam_fwd, 0.0)
    system.setConstant(lam_bwd, 0.0)

    system.add(SpaceWrapper(Vector(0, 0, 0), all))

    system.add(PerturbationConstraint(solutes))

    system.add(ComponentConstraint(lam_fwd, Min(lam + delta_lambda, 1)))
    system.add(ComponentConstraint(lam_bwd, Max(lam - delta_lambda, 0)))

    de_fwd = Symbol("de_fwd")
    de_bwd = Symbol("de_bwd")

    system.setComponent(de_fwd, fwd_nrg - total_nrg)
    system.setComponent(de_bwd, total_nrg - bwd_nrg)

    system.add("total_energy", MonitorComponent(e_total, Average()))
    system.add("de_fwd",
               MonitorComponent(de_fwd, FreeEnergyAverage(temperature)))
    system.add("de_bwd",
               MonitorComponent(de_bwd, FreeEnergyAverage(temperature)))

    system.setComponent(lam, 0.0)
    print "LAMBDA=0   : Energy = %f kcal mol-1" % system.energy().to(
        kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                     system.energy(e_bwd).to(kcal_per_mol))

    system.setComponent(lam, 0.5)
    print "LAMBDA=0.5 : Energy = %f kcal mol-1" % system.energy().to(
        kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                     system.energy(e_bwd).to(kcal_per_mol))

    system.setComponent(lam, 1.0)
    print "LAMBDA=1.0 : Energy = %f kcal mol-1" % system.energy().to(
        kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                     system.energy(e_bwd).to(kcal_per_mol))
    return system
Exemple #7
0
def loadQMMMSystem():
    """This function is called to set up the system. It sets everything
       up, then returns a System object that holds the configured system"""

    print("Loading the system...")

    t = QTime()

    if os.path.exists(s3file.val):
        print("Loading existing s3 file %s..." % s3file.val)
        loadsys = Sire.Stream.load(s3file.val)

    else:
        print("Loading from Amber files %s / %s..." %
              (topfile.val, crdfile.val))
        # Add the name of the ligand to the list of solute molecules
        sys_scheme = NamingScheme()
        sys_scheme.addSoluteResidueName(ligand_name.val)

        # Load up the system. This will automatically find the protein, solute, water, solvent
        # and ion molecules and assign them to different groups
        loadsys = createSystem(topfile.val, crdfile.val, sys_scheme)
        ligand_mol = findMolecule(loadsys, ligand_name.val)

        if ligand_mol is None:
            print(
                "Cannot find the ligand (%s) in the set of loaded molecules!" %
                ligand_name.val)
            sys.exit(-1)

        # Center the system with the ligand at (0,0,0)
        loadsys = centerSystem(loadsys, ligand_mol)
        ligand_mol = loadsys[ligand_mol.number()][0].molecule()

        if reflection_radius.val is None:
            loadsys = addFlexibility(loadsys, naming_scheme=sys_scheme)
        else:
            loadsys = addFlexibility(loadsys,
                                     Vector(0),
                                     reflection_radius.val,
                                     naming_scheme=sys_scheme)

        Sire.Stream.save(loadsys, s3file.val)

    ligand_mol = findMolecule(loadsys, ligand_name.val)

    if ligand_mol is None:
        print("Cannot find the ligand (%s) in the set of loaded molecules!" %
              ligand_name.val)
        sys.exit(-1)

    # Now build the QM/MM system
    system = System("QMMM system")

    if loadsys.containsProperty("reflection center"):
        reflect_center = loadsys.property("reflection center").toVector()[0]
        reflect_radius = float(
            str(loadsys.property("reflection sphere radius")))

        system.setProperty("reflection center",
                           AtomCoords(CoordGroup(1, reflect_center)))
        system.setProperty("reflection sphere radius",
                           VariantProperty(reflect_radius))
        space = Cartesian()
    else:
        space = loadsys.property("space")

    if loadsys.containsProperty("average solute translation delta"):
        system.setProperty("average solute translation delta", \
                           loadsys.property("average solute translation delta"))

    if loadsys.containsProperty("average solute rotation delta"):
        system.setProperty("average solute rotation delta", \
                           loadsys.property("average solute rotation delta"))

    # create a molecule group to hold all molecules
    all_group = MoleculeGroup("all")

    # create a molecule group for the ligand
    ligand_group = MoleculeGroup("ligand")
    ligand_group.add(ligand_mol)
    all_group.add(ligand_mol)

    groups = []
    groups.append(ligand_group)

    # pull out the groups that we want from the two systems

    # create a group to hold all of the fixed molecules in the bound leg
    fixed_group = MoleculeGroup("fixed_molecules")
    if MGName("fixed_molecules") in loadsys.mgNames():
        fixed_group.add(loadsys[MGName("fixed_molecules")])

    if save_pdb.val:
        # write a PDB of the fixed atoms in the bound and free legs
        if not os.path.exists(outdir.val):
            os.makedirs(outdir.val)

        PDB().write(fixed_group, "%s/fixed.pdb" % outdir.val)

    # create a group to hold all of the mobile solute molecules
    mobile_solutes_group = MoleculeGroup("mobile_solutes")
    if MGName("mobile_solutes") in loadsys.mgNames():
        mobile_solutes_group.add(loadsys[MGName("mobile_solutes")])
        mobile_solutes_group.remove(ligand_mol)
        if mobile_solutes_group.nMolecules() > 0:
            all_group.add(mobile_solutes_group)

    groups.append(mobile_solutes_group)

    # create a group to hold all of the mobile solvent molecules
    mobile_solvents_group = MoleculeGroup("mobile_solvents")
    if MGName("mobile_solvents") in loadsys.mgNames():
        mols = loadsys[MGName("mobile_solvents")]
        for molnum in mols.molNums():
            solvent_mol = mols[molnum][0].molecule()
            mobile_solvents_group.add(solvent_mol)

        all_group.add(mobile_solvents_group)

        print("The number of mobile solvent molecules is %d." %
              mobile_solvents_group.nMolecules())

    groups.append(mobile_solvents_group)

    # create the groups to hold all of the protein molecules. We will use "extract" to
    # pull out only those protein atoms that are in the mobile region
    protein_intra_group = MoleculeGroup("protein_intra_group")
    mobile_proteins_group = MoleculeGroup("proteins")
    mobile_protein_sidechains_group = MoleculeGroup("mobile_sidechains")
    mobile_protein_backbones_group = MoleculeGroup("mobile_backbones")

    if MGName("protein_sidechains") in loadsys.mgNames() or \
       MGName("protein_backbones") in loadsys.mgNames():

        all_proteins = Molecules()

        try:
            protein_sidechains = loadsys[MGName("protein_sidechains")]
            all_proteins.add(protein_sidechains.molecules())
        except:
            protein_sidechains = MoleculeGroup()

        try:
            protein_backbones = loadsys[MGName("protein_backbones")]
            all_proteins.add(protein_backbones.molecules())
        except:
            protein_backbones = MoleculeGroup()

        try:
            boundary_molecules = loadsys[MGName("boundary_molecules")]
            all_proteins.add(boundary_molecules.molecules())
        except:
            boundary_molecules = MoleculeGroup()

        for molnum in all_proteins.molNums():
            protein_mol = Molecule.join(all_proteins[molnum])

            if protein_mol.selectedAll():
                protein_intra_group.add(protein_mol)
                all_group.add(protein_mol)

                mobile_protein = []

                if protein_sidechains.contains(molnum):
                    sidechains = protein_sidechains[molnum]
                    for sidechain in sidechains:
                        mobile_protein_sidechains_group.add(sidechain)

                    mobile_protein += sidechains

                if protein_backbones.contains(molnum):
                    backbones = protein_backbones[molnum]
                    for backbone in backbones:
                        mobile_protein_backbones_group.add(backbone)

                    mobile_protein += backbones

                if len(mobile_protein) > 0:
                    mobile_proteins_group.add(Molecule.join(mobile_protein))

            else:
                # only some of the atoms have been selected. We will extract
                # the mobile atoms and will then update all of the other selections
                print("Extracting the mobile atoms of protein %s" %
                      protein_mol.molecule())
                new_protein_mol = protein_mol.extract()
                print("Extracted %d mobile atoms from %d total atoms..." % \
                                        (new_protein_mol.nAtoms(), protein_mol.molecule().nAtoms()))

                protein_intra_group.add(new_protein_mol)
                all_group.add(new_protein_mol)

                mobile_protein_view = new_protein_mol.selection()
                mobile_protein_view = mobile_protein_view.selectNone()

                if protein_sidechains.contains(molnum):
                    sidechains = protein_sidechains[molnum]

                    for sidechain in sidechains:
                        view = new_protein_mol.selection()
                        view = view.selectNone()

                        for atomid in sidechain.selection().selectedAtoms():
                            atom = protein_mol.atom(atomid)
                            resatomid = ResAtomID(atom.residue().number(),
                                                  atom.name())
                            view = view.select(resatomid)
                            mobile_protein_view = mobile_protein_view.select(
                                resatomid)

                        if view.nSelected() > 0:
                            mobile_protein_sidechains_group.add(
                                PartialMolecule(new_protein_mol, view))

                if protein_backbones.contains(molnum):
                    backbones = protein_backbones[molnum]

                    for backbone in backbones:
                        view = new_protein_mol.selection()
                        view = view.selectNone()

                        for atomid in backbone.selection().selectedAtoms():
                            atom = protein_mol.atom(atomid)
                            resatomid = ResAtomID(atom.residue().number(),
                                                  atom.name())
                            view = view.select(resatomid)
                            mobile_protein_view = mobile_protein_view.select(
                                resatomid)

                        if view.nSelected() > 0:
                            mobile_protein_backbones_group.add(
                                PartialMolecule(new_protein_mol, view))

                print("Number of moved protein sidechain residues = %s" %
                      mobile_protein_sidechains_group.nViews())
                print("Number of moved protein backbone residues = %s" %
                      mobile_protein_backbones_group.nViews())

                if mobile_protein_view.nSelected() > 0:
                    mobile_proteins_group.add(
                        PartialMolecule(new_protein_mol, mobile_protein_view))

    groups.append(mobile_protein_backbones_group)
    groups.append(mobile_protein_sidechains_group)
    groups.append(all_group)

    # finished added in all of the proteins
    for group in groups:
        if group.nMolecules() > 0:
            print("Adding group %s" % group.name())
            system.add(group)

    # now add in the forcefields for the system...
    print("Creating the forcefields for the QM/MM system...")

    # first, group together the molecules grouped above into convenient
    # groups for the forcefields

    # group holding just the ligand
    ligand_mols = ligand_group.molecules()

    # group holding all of the mobile atoms
    mobile_mols = mobile_solvents_group.molecules()
    mobile_mols.add(mobile_solutes_group.molecules())
    mobile_mols.add(protein_intra_group.molecules())

    # group holding all of the mobile atoms in the bound leg, excluding the
    # buffer atoms that are fixed, but bonded to mobile atoms
    mobile_buffered_mols = mobile_solvents_group.molecules()
    mobile_buffered_mols.add(mobile_solutes_group.molecules())
    mobile_buffered_mols.add(mobile_proteins_group.molecules())

    # group holding all of the protein molecules that need intramolecular terms calculated
    protein_intra_mols = protein_intra_group.molecules()

    # group holding all of the solute molecules that nede intramolecular terms calculated
    solute_intra_mols = mobile_solutes_group.molecules()

    forcefields = []

    ###
    ### INTRA-ENERGY OF THE LIGAND AND CLUSTER
    ###

    # intramolecular energy of the ligand
    ligand_intraclj = IntraCLJFF("ligand:intraclj")
    ligand_intraclj = setCLJProperties(ligand_intraclj, space)
    ligand_intraclj.add(ligand_mols)

    ligand_intraff = InternalFF("ligand:intra")
    ligand_intraff.add(ligand_mols)

    forcefields.append(ligand_intraclj)
    forcefields.append(ligand_intraff)

    ligand_mm_nrg = ligand_intraclj.components().total(
    ) + ligand_intraff.components().total()

    ###
    ### FORCEFIELDS INVOLVING THE LIGAND/CLUSTER AND OTHER ATOMS
    ###

    # forcefield holding the energy between the ligand and the mobile atoms in the
    # bound leg
    ligand_mobile = InterGroupCLJFF("system:ligand-mobile")
    ligand_mobile = setCLJProperties(ligand_mobile, space)

    ligand_mobile.add(ligand_mols, MGIdx(0))
    ligand_mobile.add(mobile_mols, MGIdx(1))

    qm_ligand = QMMMFF("system:ligand-QM")
    qm_ligand.add(ligand_mols, MGIdx(0))
    qm_ligand = setQMProperties(qm_ligand, space)

    zero_energy = 0

    if not intermolecular_only.val:
        if qm_zero_energy.val is None:
            # calculate the delta value for the system - this is the difference between
            # the MM and QM intramolecular energy of the ligand
            t.start()
            print("\nComparing the MM and QM energies of the ligand...")
            mm_intra = ligand_intraclj.energy().value(
            ) + ligand_intraff.energy().value()
            print("MM energy = %s kcal mol-1 (took %s ms)" %
                  (mm_intra, t.elapsed()))

            t.start()
            zero_sys = System()
            zero_sys.add(qm_ligand)
            qm_intra = zero_sys.energy().value()
            print("QM energy = %s kcal mol-1 (took %s ms)" %
                  (qm_intra, t.elapsed()))

            print("\nSetting the QM zero energy to %s kcal mol-1" %
                  (qm_intra - mm_intra))
            qm_ligand.setZeroEnergy((qm_intra - mm_intra) * kcal_per_mol)
            zero_energy = qm_intra - mm_intra
        else:
            print("\nManually setting the QM zero energy to %s" %
                  qm_zero_energy.val)
            qm_ligand.setZeroEnergy(qm_zero_energy.val)
            zero_energy = qm_zero_energy.val

    qm_ligand.add(mobile_mols, MGIdx(1))

    ligand_mm_nrg += ligand_mobile.components().total()
    ligand_qm_nrg = qm_ligand.components().total() + ligand_mobile.components(
    ).lj()

    if intermolecular_only.val:
        # the QM model still uses the MM intramolecular energy of the ligand
        ligand_qm_nrg += ligand_intraclj.components().total(
        ) + ligand_intraff.components().total()

    forcefields.append(ligand_mobile)
    forcefields.append(qm_ligand)

    if fixed_group.nMolecules() > 0:
        # there are fixed molecules

        # Whether or not to disable the grid and calculate all energies atomisticly
        if disable_grid:
            # we need to renumber all of the fixed molecules so that they don't clash
            # with the mobile molecules
            print("Renumbering fixed molecules...")
            fixed_group = renumberMolecules(fixed_group)

        # forcefield holding the energy between the ligand and the fixed atoms in the bound leg
        if disable_grid:
            ligand_fixed = InterGroupCLJFF("system:ligand-fixed")
            ligand_fixed = setCLJProperties(ligand_fixed, space)
            ligand_fixed = setFakeGridProperties(ligand_fixed, space)

            ligand_fixed.add(ligand_mols, MGIdx(0))
            ligand_fixed.add(fixed_group, MGIdx(1))

            qm_ligand.add(fixed_group, MGIdx(1))

            ligand_mm_nrg += ligand_fixed.components().total()
            ligand_qm_nrg += ligand_fixed.components().lj()

            forcefields.append(ligand_fixed)

        else:
            ligand_fixed = GridFF2("system:ligand-fixed")
            ligand_fixed = setCLJProperties(ligand_fixed, space)
            ligand_fixed = setGridProperties(ligand_fixed)

            ligand_fixed.add(ligand_mols, MGIdx(0))
            ligand_fixed.addFixedAtoms(fixed_group)

            qm_ligand.addFixedAtoms(fixed_group)

            ligand_mm_nrg += ligand_fixed.components().total()
            ligand_qm_nrg += ligand_fixed.components().lj()

            forcefields.append(ligand_fixed)

    ###
    ### FORCEFIELDS NOT INVOLVING THE LIGAND
    ###

    # forcefield holding the intermolecular energy between all molecules
    mobile_mobile = InterCLJFF("mobile-mobile")
    mobile_mobile = setCLJProperties(mobile_mobile, space)

    mobile_mobile.add(mobile_mols)

    other_nrg = mobile_mobile.components().total()
    forcefields.append(mobile_mobile)

    # forcefield holding the energy between the mobile atoms and
    # the fixed atoms
    if disable_grid.val:
        mobile_fixed = InterGroupCLJFF("mobile-fixed")
        mobile_fixed = setCLJProperties(mobile_fixed)
        mobile_fixed = setFakeGridProperties(mobile_fixed, space)
        mobile_fixed.add(mobile_buffered_mols, MGIdx(0))
        mobile_fixed.add(fixed_group, MGIdx(1))
        other_nrg += mobile_fixed.components().total()
        forcefields.append(mobile_fixed)
    else:
        mobile_fixed = GridFF2("mobile-fixed")
        mobile_fixed = setCLJProperties(mobile_fixed, space)
        mobile_fixed = setGridProperties(mobile_fixed)

        # we use mobile_buffered_group as this group misses out atoms that are bonded
        # to fixed atoms (thus preventing large energies caused by incorrect non-bonded calculations)
        mobile_fixed.add(mobile_buffered_mols, MGIdx(0))
        mobile_fixed.addFixedAtoms(fixed_group)
        other_nrg += mobile_fixed.components().total()
        forcefields.append(mobile_fixed)

    # intramolecular energy of the protein
    if protein_intra_mols.nMolecules() > 0:
        protein_intraclj = IntraCLJFF("protein_intraclj")
        protein_intraclj = setCLJProperties(protein_intraclj, space)

        protein_intraff = InternalFF("protein_intra")

        for molnum in protein_intra_mols.molNums():
            protein_mol = Molecule.join(protein_intra_mols[molnum])
            protein_intraclj.add(protein_mol)
            protein_intraff.add(protein_mol)

        other_nrg += protein_intraclj.components().total()
        other_nrg += protein_intraff.components().total()
        forcefields.append(protein_intraclj)
        forcefields.append(protein_intraff)

    # intramolecular energy of any other solutes
    if solute_intra_mols.nMolecules() > 0:
        solute_intraclj = IntraCLJFF("solute_intraclj")
        solute_intraclj = setCLJProperties(solute_intraclj, space)

        solute_intraff = InternalFF("solute_intra")

        for molnum in solute_intra_mols.molNums():
            solute_mol = Molecule.join(solute_intra_mols[molnum])
            solute_intraclj.add(solute_mol)
            solute_intraff.add(solute_mol)

        other_nrg += solute_intraclj.components().total()
        other_nrg += solute_intraff.components().total()
        forcefields.append(solute_intraclj)
        forcefields.append(solute_intraff)

    ###
    ### NOW ADD THE FORCEFIELDS TO THE SYSTEM
    ###
    ###
    ### SETTING THE FORCEFIELD EXPRESSIONS
    ###

    lam = Symbol("lambda")

    e_slow = ((1 - lam) * ligand_qm_nrg) + (lam * ligand_mm_nrg) + other_nrg
    e_fast = ligand_mm_nrg + other_nrg

    de_by_dlam = ligand_mm_nrg - ligand_qm_nrg

    for forcefield in forcefields:
        system.add(forcefield)

    system.setConstant(lam, 0.0)

    system.setComponent(Symbol("E_{fast}"), e_fast)
    system.setComponent(Symbol("E_{slow}"), e_slow)
    system.setComponent(Symbol("dE/dlam"), de_by_dlam)
    system.setComponent(system.totalComponent(), e_slow)

    system.setProperty("space", space)

    if space.isPeriodic():
        # ensure that all molecules are wrapped into the space with the ligand at the center
        print("Adding in a space wrapper constraint %s, %s" %
              (space, ligand_mol.evaluate().center()))
        system.add(SpaceWrapper(ligand_mol.evaluate().center(), all_group))
        system.applyConstraints()

    print("\nHere are the values of all of the initial energy components...")
    t.start()
    printEnergies(system.energies())
    print("(these took %d ms to evaluate)\n" % t.elapsed())

    # Create a monitor to monitor the free energy average
    system.add("dG/dlam",
               MonitorComponent(Symbol("dE/dlam"), AverageAndStddev()))

    if intermolecular_only.val:
        print(
            "\n\n## This simulation uses QM to model *only* the intermolecular energy between"
        )
        print(
            "## the QM and MM atoms. The intramolecular energy of the QM atoms is still"
        )
        print("## modelled using MM.\n")
    else:
        print(
            "\n\n## This simulation uses QM to model both the intermolecular and intramolecular"
        )
        print(
            "## energies of the QM atoms. Because the this, we have to adjust the 'zero' point"
        )
        print(
            "## of the QM potential. You need to add the value %s kcal mol-1 back onto the"
            % zero_energy)
        print("## QM->MM free energy calculated using this program.\n")

    return system
Exemple #8
0
def makeSim(system, ligand_mol, watersys):
    """Create simulation systems with and without the ligand and return those systems together
       with the moves"""

    stage1 = System("with_ligand")
    stage2 = System("without_ligand")

    if system.containsProperty("reflection center"):
        reflection_center = system.property("reflection center").toVector()[0]
        reflection_radius = float(str(system.property("reflection sphere radius")))

        stage1.setProperty("reflection center", AtomCoords(CoordGroup(1,reflection_center)))
        stage1.setProperty("reflection sphere radius", VariantProperty(reflection_radius))

        stage2.setProperty("reflection center", AtomCoords(CoordGroup(1,reflection_center)))
        stage2.setProperty("reflection sphere radius", VariantProperty(reflection_radius))

    # create a molecule group for fixed atoms (everything except the mobile water)
    fixed_group = MoleculeGroup("fixed")

    if MGName("fixed_molecules") in system.mgNames():
        fixed_group.add( system[ MGName("fixed_molecules") ] )

    if MGName("mobile_solutes") in system.mgNames():
        fixed_group.add( system[MGName("mobile_solutes")] )

    if MGName("protein_sidechains") in system.mgNames() or \
       MGName("protein_backbones") in system.mgNames():

        all_proteins = Molecules()

        try:
            protein_sidechains = system[MGName("protein_sidechains")]
            all_proteins.add(protein_sidechains.molecules())
        except:
            pass

        try:
            protein_backbones = system[MGName("protein_backbones")]
            all_proteins.add(protein_backbones.molecules())
        except:
            pass

        try:
            boundary_molecules = system[MGName("boundary_molecules")]
            all_proteins.add(boundary_molecules.molecules())
        except:
            pass

        for molnum in all_proteins.molNums():
            protein_mol = all_proteins[molnum].join()
            fixed_group.add(protein_mol)

    stage1_fixed_group = MoleculeGroup(fixed_group)
    stage2_fixed_group = MoleculeGroup(fixed_group)

    stage1_fixed_group.add(ligand_mol)
    stage2_fixed_group.remove(ligand_mol)

    mobile_group = MoleculeGroup("mobile_group")
    if MGName("mobile_solvents") in system.mgNames():
        mobile_group.add( system[MGName("mobile_solvents")] )

    stage1_mobile_group = MoleculeGroup(mobile_group)
    stage2_mobile_group = MoleculeGroup(mobile_group)

    # now find water molecules from the water system that can be substituted for the ligand
    watermols = findOverlappingWaters(ligand_mol, watersys)

    stage2_mobile_group.add(watermols)

    print("The number of stage 1 fixed non-solvent molecules is %d." % stage1_fixed_group.nMolecules())
    print("The number of stage 1 mobile solvent molecules is %d." % stage1_mobile_group.nMolecules())

    print("The number of stage 2 fixed non-solvent molecules is %d." % stage2_fixed_group.nMolecules())
    print("The number of stage 2 mobile solvent molecules is %d." % stage2_mobile_group.nMolecules())

    # write a PDB of all of the fixed molecules
    PDB().write(stage1_mobile_group, "stage1_mobile_atoms.pdb")
    PDB().write(stage2_mobile_group, "stage2_mobile_atoms.pdb")
    PDB().write(stage1_fixed_group, "stage1_fixed_atoms.pdb")
    PDB().write(stage2_fixed_group, "stage2_fixed_atoms.pdb")

    # create the forcefields

    if use_fast_ff.val:
        stage1_ff = InterFF("ff")
        stage2_ff = InterFF("ff")
        stage1_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val) )
        stage2_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val) )
        
        if disable_grid.val:
            stage1_ff.disableGrid()
            stage2_ff.disableGrid()
        else:
            stage1_ff.enableGrid()
            stage1_ff.setGridSpacing(grid_spacing.val)
            stage1_ff.setGridBuffer(grid_buffer.val)
            stage2_ff.enableGrid()
            stage2_ff.setGridSpacing(grid_spacing.val)
            stage2_ff.setGridBuffer(grid_buffer.val)

        stage1_ff.add(stage1_mobile_group)
        stage1_ff.setFixedAtoms(stage1_fixed_group.molecules())
        stage2_ff.add(stage2_mobile_group)
        stage2_ff.setFixedAtoms(stage2_fixed_group.molecules())

        stage1.add(stage1_ff)
        stage1.setComponent(stage1.totalComponent(), stage1_ff.components().total())
        stage2.add(stage1_ff)
        stage2.setComponent(stage2.totalComponent(), stage2_ff.components().total())

    else:
        # forcefield holding the energy between the mobile atoms and  
        # the fixed atoms
        if disable_grid.val:
            stage1_mobile_fixed = InterGroupCLJFF("mobile-fixed")
            stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed)
            stage1_mobile_fixed = setFakeGridProperties(stage1_mobile_fixed)
            stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0))
            stage1_mobile_fixed.add(stage1_fixed_group, MGIdx(1))

            stage2_mobile_fixed = InterGroupCLJFF("mobile-fixed")
            stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed)
            stage2_mobile_fixed = setFakeGridProperties(stage2_mobile_fixed)
            stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0))
            stage2_mobile_fixed.add(stage2_fixed_group, MGIdx(1))
        else:
            stage1_mobile_fixed = GridFF("mobile-fixed")
            stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed)
            stage1_mobile_fixed = setGridProperties(stage1_mobile_fixed)

            stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0))
            stage1_mobile_fixed.addFixedAtoms(stage1_fixed_group)

            stage2_mobile_fixed = GridFF("mobile-fixed")
            stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed)
            stage2_mobile_fixed = setGridProperties(stage2_mobile_fixed)

            stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0))
            stage2_mobile_fixed.addFixedAtoms(stage2_fixed_group)

        # forcefield holding the energy between fixed atoms
        stage1_mobile_mobile = InterCLJFF("mobile-mobile")
        stage1_mobile_mobile = setCLJProperties(stage1_mobile_mobile)
        stage1_mobile_mobile.add(stage1_mobile_group)

        stage2_mobile_mobile = InterCLJFF("mobile-mobile")
        stage2_mobile_mobile = setCLJProperties(stage2_mobile_mobile)
        stage2_mobile_mobile.add(stage2_mobile_group)

        stage1.add(stage1_mobile_group)
        stage1.add(stage1_mobile_fixed)
        stage1.add(stage1_mobile_mobile)

        stage2.add(stage2_mobile_group)
        stage2.add(stage2_mobile_fixed)
        stage2.add(stage2_mobile_mobile)

        stage1.setComponent(stage1.totalComponent(), stage1_mobile_mobile.components().total() + stage1_mobile_fixed.components().total())
        stage2.setComponent(stage2.totalComponent(), stage2_mobile_mobile.components().total() + stage2_mobile_fixed.components().total())

    stage1.add(stage1_mobile_group)
    stage2.add(stage2_mobile_group)

    stage1.add("volume_map", VolMapMonitor(stage1_mobile_group), 1000)
    stage2.add("volume_map", VolMapMonitor(stage2_mobile_group), 1000)

    max_water_translation = 0.15 * angstroms
    max_water_rotation = 15 * degrees

    stage1_moves = WeightedMoves()

    if stage1_mobile_group.nViews() > 0:
        rb_moves = RigidBodyMC(stage1_mobile_group)
        rb_moves.setMaximumTranslation(max_water_translation)
        rb_moves.setMaximumRotation(max_water_rotation)

        if stage1.containsProperty("reflection sphere radius"):
            reflection_radius = float(str(stage1.property("reflection sphere radius"))) * angstroms
            reflection_center = stage1.property("reflection center").toVector()[0]
            rb_moves.setReflectionSphere(reflection_center, reflection_radius)

        stage1_moves.add(rb_moves, stage1_mobile_group.nViews())

    stage2_moves = WeightedMoves()

    if stage2_mobile_group.nViews() > 0:
        rb_moves = RigidBodyMC(stage2_mobile_group)
        rb_moves.setMaximumTranslation(max_water_translation)
        rb_moves.setMaximumRotation(max_water_rotation)

        if stage2.containsProperty("reflection sphere radius"):
            reflection_radius = float(str(stage2.property("reflection sphere radius"))) * angstroms
            reflection_center = stage2.property("reflection center").toVector()[0]
            rb_moves.setReflectionSphere(reflection_center, reflection_radius)

        stage2_moves.add(rb_moves, stage2_mobile_group.nViews())

    stage1_moves.setTemperature(temperature.val)
    stage2_moves.setTemperature(temperature.val)

    seed = random_seed.val

    if seed is None:
        seed = RanGenerator().randInt(100000,1000000)
        print("Using generated random number seed %d" % seed)
    else:
        print("Using supplied random number seed %d" % seed)
    
    stage1_moves.setGenerator( RanGenerator(seed) )
    stage2_moves.setGenerator( RanGenerator(seed+7) )

    return ( (stage1,stage1_moves), (stage2,stage2_moves) )
Exemple #9
0
for forcefield in forcefields:
    system.add(forcefield)

system.setProperty( "space", space )
system.setProperty( "switchingFunction", 
                    HarmonicSwitchingFunction(coulomb_cutoff, coulomb_feather,
                                              lj_cutoff, lj_feather) )
system.setProperty( "combiningRules", VariantProperty(combining_rules) )

total_nrg = solute_intraclj.components().total() + solute_intraff.components().total() +\
    solventff.components().total() + solute_solventff.components().total() +\
    protein_intraclj.components().total() + protein_intraff.components().total() + \
    solute_proteinff.components().total() + protein_solventff.components().total() 

e_total = system.totalComponent()
system.setComponent( e_total, total_nrg )

# Add a space wrapper that wraps all molecules into the box centered at (0,0,0)
#system.add( SpaceWrapper(Vector(0,0,0), all) )

print("\nTotal energy ")
print(system.energy())

print("Components energies ")
for component in list(system.energyComponents().keys()):
    print(component, system.energyComponents().value(component) * kcal_per_mol)

# Note that tip3p water are likely to have bonds between hydrogen atoms.
PDB().write(all, "out.pdb")

print("The AMBER11/sander energies for this system are ") 
Exemple #10
0
                    .setProperty("charge", charges) \
                    .setProperty("LJ", ljs) \
             .commit()

    cljff.add(mol)

ms = t.elapsed()
print(("Parameterised all of the water molecules (in %d ms)!" % ms))

system = System()

system.add(cljff)

lam = Symbol("lambda")

system.setComponent( lam, 0.2 )
system.setComponent( system.totalComponent(), lam * cljff.components().total() )

mc = RigidBodyMC(cljff.group(MGIdx(0)))

moves = SameMoves(mc)

def testStream(c):
    t.start()

    data = Sire.Stream.save(c)

    ms = t.elapsed()

    print(("Streaming %s took %d ms" % (c.what(), ms)))
    print(("%s takes up %d bytes" % (c.what(),data.size())))
Exemple #11
0
def test_nrg(verbose=False):

    top_file = "../io/ose.top"
    crd_file = "../io/ose.crd"

    amber = Amber()
    molecules, space = amber.readCrdTop(crd_file, top_file)
    # Overload, we want to calc the energy in a non periodic box for comparison with Sander
    space = Cartesian()

    moleculeNumbers = molecules.molNums()
    moleculeList = []

    for moleculeNumber in moleculeNumbers:
        molecule = molecules.molecule(moleculeNumber).molecule()
        moleculeList.append(molecule)

    system = System()

    solute = MoleculeGroup("solute", moleculeList[0])

    # Add these groups to the System
    system.add(solute)

    # Now solute bond, angle, dihedral energy
    solute_intraff = InternalFF("solute_intraff")
    solute_intraff.add(solute)

    # Now solute intramolecular CLJ energy
    solute_intraclj = IntraCLJFF("solute_intraclj")
    solute_intraclj.add(solute)

    # Here is the list of all forcefields
    forcefields = [solute_intraff, solute_intraclj]

    # Add these forcefields to the system
    for forcefield in forcefields:
        system.add(forcefield)

    system.setProperty("space", space)
    system.setProperty(
        "switchingFunction",
        HarmonicSwitchingFunction(coulomb_cutoff, coulomb_feather, lj_cutoff,
                                  lj_feather))
    system.setProperty("combiningRules", VariantProperty(combining_rules))

    total_nrg = solute_intraclj.components().total(
    ) + solute_intraff.components().total()

    e_total = system.totalComponent()
    system.setComponent(e_total, total_nrg)

    if verbose:
        print("\nTotal energy ")
        print(system.energy())

        print("Components energies ")
        for component in list(system.energyComponents().keys()):
            print(component,
                  system.energyComponents().value(component) * kcal_per_mol)

        print("The AMBER14/sander energies for this system are ")
        print("""
   NSTEP       ENERGY          RMS            GMAX         NAME    NUMBER
      1      -3.4880E+01     1.3388E+01     6.2845E+01     C2         20

 BOND    =        5.1844  ANGLE   =       10.0783  DIHED      =       20.1271
 VDWAALS =       -1.7278  EEL     =     -256.9757  HBOND      =        0.0000
 1-4 VDW =       10.6377  1-4 EEL =      177.7958  RESTRAINT  =        0.0000
""")

        diff = abs(-34.880 - system.energy().value())
        print("Difference = %s" % diff)

    e_bond = system.energy(solute_intraff.components().bond()).value()
    e_ang = system.energy(solute_intraff.components().angle()).value()
    e_dih = system.energy( solute_intraff.components().dihedral() ).value() + \
            system.energy( solute_intraff.components().improper() ).value()

    assert_almost_equal(e_bond, 5.1844, 2)
    assert_almost_equal(e_ang, 10.0783, 2)
    assert_almost_equal(e_dih, 20.1271, 2)

    e_coul = system.energy(solute_intraclj.components().coulomb()).value()
    e_lj = system.energy(solute_intraclj.components().lj()).value()

    assert_almost_equal(e_coul, -256.9757 + 177.7958, 2)
    assert_almost_equal(e_lj, -1.7278 + 10.6377, 2)

    assert_almost_equal(system.energy().value(), -34.880, 2)
Exemple #12
0
cljff.add(swapwaters, MGIdx(0))
cljff.add(waters, MGIdx(1))
cljff.setSpace( Cartesian() )
cljff.setShiftElectrostatics(True)

swap_swapff = InterCLJFF("swap-swap")
swap_swapff.setSpace(Cartesian())
swap_swapff.setSwitchingFunction( HarmonicSwitchingFunction(25*angstrom, 25*angstrom, 10*angstrom, 10*angstrom) )
swap_swapff.add(swapwaters)
grid_system.add(swap_swapff)
exp_system.add(swap_swapff)

grid_system.add(gridff)
exp_system.add(cljff)

grid_system.setComponent( grid_system.totalComponent(),  \
                          gridff.components().total() + swap_swapff.components().total() )
exp_system.setComponent( exp_system.totalComponent(), \
                              cljff.components().total() + swap_swapff.components().total() )

print((grid_system.energies()))
print((exp_system.energies()))

print(("\nGrid energy equals: %s. Explicit energy equals: %s." % \
          (grid_system.energy(), exp_system.energy())))

diff = grid_system.energy() - exp_system.energy()
print(("The difference is %s\n" % diff))

rbmc = RigidBodyMC(swapwaters)
rbmc.setReflectionSphere(center_point, 7.5*angstrom)
Exemple #13
0
gridff2.setSpace( Cartesian() )
gridff2.setShiftElectrostatics(True)
#gridff2.setUseReactionField(True)
#gridff2.setUseAtomisticCutoff(True)

swap_swapff = InterCLJFF("swap-swap")
swap_swapff.setSpace(Cartesian())
swap_swapff.setSwitchingFunction( HarmonicSwitchingFunction(25*angstrom, 25*angstrom, 10*angstrom, 10*angstrom) )
swap_swapff.add(swapwaters)
grid_system.add(swap_swapff)
grid_system2.add(swap_swapff)

grid_system.add(gridff)
grid_system2.add(gridff2)

grid_system.setComponent( grid_system.totalComponent(),  \
                          gridff.components().total() + swap_swapff.components().total() )
grid_system2.setComponent( grid_system2.totalComponent(), \
                           gridff2.components().total() + swap_swapff.components().total() )

print(grid_system.energies())
print(grid_system2.energies())

print("\nOld Grid energy equals: %s. New GridFF energy equals: %s." % \
          (grid_system.energy(), grid_system2.energy()))

diff = grid_system.energy() - grid_system2.energy()
print("The difference is %s\n" % diff)

rbmc = RigidBodyMC(swapwaters)
rbmc.setReflectionSphere(center_point, 7.5*angstrom)
Exemple #14
0
def createSystem():
    protomsdir = "%s/Work/ProtoMS" % os.getenv("HOME")

    protoms = ProtoMS( "%s/protoms2" % protomsdir )

    protoms.addParameterFile( "%s/parameter/amber99.ff" % protomsdir )
    protoms.addParameterFile( "%s/parameter/solvents.ff" % protomsdir )
    protoms.addParameterFile( "%s/parameter/gaff.ff" % protomsdir )
    protoms.addParameterFile( solute_params )

    solute = PDB().readMolecule(solute_file)
    solute = solute.edit().rename(solute_name).commit()
    solute = protoms.parameterise(solute, ProtoMS.SOLUTE)

    perturbation = solute.property("perturbations")

    lam = Symbol("lambda")
    lam_fwd = Symbol("lambda_{fwd}")
    lam_bwd = Symbol("lambda_{bwd}")

    initial = Perturbation.symbols().initial()
    final = Perturbation.symbols().final()

    solute = solute.edit().setProperty("perturbations",
                perturbation.recreate( (1-lam)*initial + lam*final ) ).commit()

    solute_fwd = solute.edit().renumber().setProperty("perturbations",
                perturbation.substitute( lam, lam_fwd ) ).commit()
    solute_bwd = solute.edit().renumber().setProperty("perturbations",
                perturbation.substitute( lam, lam_bwd ) ).commit()

    solvent = PDB().read(solvent_file)

    tip4p = solvent.moleculeAt(0).molecule()
    tip4p = tip4p.edit().rename(solvent_name).commit()
    tip4p = protoms.parameterise(tip4p, ProtoMS.SOLVENT)

    tip4p_chgs = tip4p.property("charge")
    tip4p_ljs = tip4p.property("LJ")

    for i in range(0,solvent.nMolecules()):
        tip4p = solvent.moleculeAt(i).molecule()
        tip4p = tip4p.edit().rename(solvent_name) \
                            .setProperty("charge", tip4p_chgs) \
                            .setProperty("LJ", tip4p_ljs) \
                            .commit()

        solvent.update(tip4p)

    system = System()

    solutes = MoleculeGroup("solutes")
    solutes.add(solute)
    solutes.add(solute_fwd)
    solutes.add(solute_bwd)

    solvent = MoleculeGroup("solvent", solvent)

    all = MoleculeGroup("all")
    all.add(solutes)
    all.add(solvent)

    system.add(solutes)
    system.add(solvent)
    system.add(all)

    solventff = InterCLJFF("solvent:solvent")
    solventff.add(solvent)

    solute_intraff = InternalFF("solute_intraff")
    solute_intraff.add(solute)

    solute_fwd_intraff = InternalFF("solute_fwd_intraff")
    solute_fwd_intraff.add(solute_fwd)

    solute_bwd_intraff = InternalFF("solute_bwd_intraff")
    solute_bwd_intraff.add(solute_bwd)

    solute_intraclj = IntraCLJFF("solute_intraclj")
    solute_intraclj.add(solute)

    solute_fwd_intraclj = IntraCLJFF("solute_fwd_intraclj")
    solute_fwd_intraclj.add(solute_fwd)

    solute_bwd_intraclj = IntraCLJFF("solute_bwd_intraclj")
    solute_bwd_intraclj.add(solute_bwd)

    solute_solventff = InterGroupCLJFF("solute:solvent")
    solute_solventff.add(solute, MGIdx(0))
    solute_solventff.add(solvent, MGIdx(1))

    solute_fwd_solventff = InterGroupCLJFF("solute_fwd:solvent")
    solute_fwd_solventff.add(solute_fwd, MGIdx(0))
    solute_fwd_solventff.add(solvent, MGIdx(1))

    solute_bwd_solventff = InterGroupCLJFF("solute_bwd:solvent")
    solute_bwd_solventff.add(solute_bwd, MGIdx(0))
    solute_bwd_solventff.add(solvent, MGIdx(1))

    forcefields = [ solventff, solute_intraff, solute_intraclj, solute_solventff,
                               solute_fwd_intraff, solute_fwd_intraclj, solute_fwd_solventff,
                               solute_bwd_intraff, solute_bwd_intraclj, solute_bwd_solventff ]

    for forcefield in forcefields:
        system.add(forcefield)

    xsc_line = open(solvent_file, "r").readlines()[0]
    words = xsc_line.split()

    #HEADER box  -12.5  -12.5  -12.5   12.5   12.5   12.5
    space = PeriodicBox( Vector( float(words[2]), float(words[3]), float(words[4]) ),
                         Vector( float(words[5]), float(words[6]), float(words[7]) ) )

    system.setProperty( "space", space )
    system.setProperty( "switchingFunction", 
                        HarmonicSwitchingFunction(coulomb_cutoff, coulomb_feather,
                                              lj_cutoff, lj_feather) )
    system.setProperty( "combiningRules", VariantProperty(combining_rules) )

    e_total = system.totalComponent()
    e_fwd = Symbol("E_{fwd}")
    e_bwd = Symbol("E_{bwd}")

    total_nrg = solventff.components().total() + \
                solute_intraclj.components().total() + solute_intraff.components().total() + \
                solute_solventff.components().total()

    fwd_nrg = solventff.components().total() + \
              solute_fwd_intraclj.components().total() + solute_fwd_intraff.components().total() + \
              solute_fwd_solventff.components().total()

    bwd_nrg = solventff.components().total() + \
              solute_bwd_intraclj.components().total() + solute_bwd_intraff.components().total() + \
              solute_bwd_solventff.components().total()

    system.setComponent( e_total, total_nrg )
    system.setComponent( e_fwd, fwd_nrg )
    system.setComponent( e_bwd, bwd_nrg )

    system.setConstant(lam, 0.0)
    system.setConstant(lam_fwd, 0.0)
    system.setConstant(lam_bwd, 0.0)

    system.add( SpaceWrapper(Vector(0,0,0), all) )

    system.add( PerturbationConstraint(solutes) )

    system.add( ComponentConstraint( lam_fwd, Min( lam + delta_lambda, 1 ) ) )
    system.add( ComponentConstraint( lam_bwd, Max( lam - delta_lambda, 0 ) ) )

    de_fwd = Symbol("de_fwd")
    de_bwd = Symbol("de_bwd")

    system.setComponent( de_fwd, fwd_nrg - total_nrg )
    system.setComponent( de_bwd, total_nrg - bwd_nrg )

    system.add( "total_energy", MonitorComponent(e_total, Average()) )
    system.add( "de_fwd", MonitorComponent(de_fwd, FreeEnergyAverage(temperature)) )
    system.add( "de_bwd", MonitorComponent(de_bwd, FreeEnergyAverage(temperature)) )

    system.setComponent(lam, 0.0)
    print "LAMBDA=0   : Energy = %f kcal mol-1" % system.energy().to(kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                   system.energy(e_bwd).to(kcal_per_mol))

    system.setComponent(lam, 0.5)
    print "LAMBDA=0.5 : Energy = %f kcal mol-1" % system.energy().to(kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                   system.energy(e_bwd).to(kcal_per_mol))

    system.setComponent(lam, 1.0)
    print "LAMBDA=1.0 : Energy = %f kcal mol-1" % system.energy().to(kcal_per_mol)
    print "             (%f, %f)" % (system.energy(e_fwd).to(kcal_per_mol),
                                   system.energy(e_bwd).to(kcal_per_mol))
    return system
Exemple #15
0
    mol = mols.moleculeAt(i).molecule()

    mol = mol.edit().rename("T4P") \
                    .setProperty("charge", charges) \
                    .setProperty("LJ", ljs) \
             .commit()

    cljff.add(mol)

system = System()

system.add(cljff)

lam = Symbol("lambda")

system.setComponent( lam, 0.2 )
system.setComponent( system.totalComponent(), lam * cljff.components().total() )

mc = RigidBodyMC(cljff.group(MGIdx(0)))

moves = SameMoves(mc)

def test_stream(verbose=False):
    if verbose:
        print("saving system...")

    data = Sire.Stream.save(system)

    if verbose:
        print(("%s takes up %d bytes" % (system.what(),data.size())))
    residues.add(residue)

# need to calculate required energy using differences as old IntraCLJFF is buggy!
oldsys = System()
oldsys.add(ligmol)
oldsys.add(residues)
oldsys.add(oldff)
oldsys.add(old0ff)
oldsys.add(old1ff)

etotal = Symbol("E_{total}")
ecoul = Symbol("E_{coul}")
elj = Symbol("E_{lj}")

oldsys.setComponent( etotal, oldff.components().total() - \
                            old0ff.components().total() - \
                            old1ff.components().total() )

if oldsys.totalComponent() != etotal:
    oldsys.setComponent( oldsys.totalComponent(), etotal )

oldsys.setComponent( ecoul, oldff.components().coulomb() - \
                            old0ff.components().coulomb() - \
                            old1ff.components().coulomb() )
oldsys.setComponent( elj, oldff.components().lj() - \
                          old0ff.components().lj() - \
                          old1ff.components().lj() )

newsys = System()
newsys.add(ligmol)
newsys.add(residues)
def calculateEnergy(lamval):
    cljff01 = InterGroupCLJFF("cljff01")
    cljff02 = InterGroupCLJFF("cljff02")

    cljff01.add(water0, MGIdx(0))
    cljff01.add(water1, MGIdx(1))

    cljff02.add(water0, MGIdx(0))
    cljff02.add(water2, MGIdx(1))

    soft_cljff01 = InterGroupSoftCLJFF("soft_cljff01")
    soft_cljff02 = InterGroupSoftCLJFF("soft_cljff02")

    soft_cljff01.add(water0, MGIdx(0))
    soft_cljff01.add(water1, MGIdx(1))

    soft_cljff02.add(water0, MGIdx(0))
    soft_cljff02.add(water2, MGIdx(1))

    ref = MoleculeGroup("ref", water0)
    group_a = MoleculeGroup("group_a", water1)
    group_b = MoleculeGroup("group_b", water2)

    dlam = 0.001
    lamval_f = lamval + dlam

    lam = Symbol("lambda")
    lam_f = Symbol("lambda_f")

    soft_nrg = (1 - lam) * soft_cljff01.components().total(
        0) + lam * soft_cljff02.components().total(0)
    soft_nrg_f = (1 - lam_f) * soft_cljff01.components().total(
        1) + lam_f * soft_cljff02.components().total(1)

    de_soft = soft_nrg_f - soft_nrg

    nrg = ((1 - lam) *
           cljff01.components().total()) + (lam * cljff02.components().total())
    nrg_f = ((1 - lam_f) * cljff01.components().total()) + (
        lam_f * cljff02.components().total())

    de = nrg_f - nrg

    soft_cljff01.setProperty("alpha0", VariantProperty(lamval))
    soft_cljff02.setProperty("alpha0", VariantProperty(1 - lamval))
    soft_cljff01.setProperty("alpha1", VariantProperty(lamval_f))
    soft_cljff02.setProperty("alpha1", VariantProperty(1 - lamval_f))

    soft_cljff01.setProperty("coulombPower", VariantProperty(0))
    soft_cljff01.setProperty("shiftDelta", VariantProperty(1.1))
    soft_cljff02.setProperty("coulombPower", VariantProperty(0))
    soft_cljff02.setProperty("shiftDelta", VariantProperty(1.1))

    sys = System()
    sys.add(cljff01)
    sys.add(cljff02)
    sys.add(soft_cljff01)
    sys.add(soft_cljff02)
    sys.add(ref)
    sys.add(group_a)
    sys.add(group_b)
    sys.setComponent(lam, lamval)
    sys.setComponent(lam_f, lamval_f)
    sys.setComponent(sys.totalComponent(), nrg)
    sys.setComponent(Symbol("E_{total_f}"), nrg_f)
    sys.setComponent(Symbol("dE"), de)
    sys.setComponent(Symbol("E_soft_{total}"), soft_nrg)
    sys.setComponent(Symbol("E_soft_{total_f}"), soft_nrg_f)
    sys.setComponent(Symbol("dE_soft"), de_soft)

    nrgmon = FreeEnergyMonitor(ref, group_a, group_b)

    soft_nrgmon = FreeEnergyMonitor(ref, group_a, group_b)
    soft_nrgmon.setCoulombPower(0)
    soft_nrgmon.setShiftDelta(1.1)

    sys.add("nrgmon", nrgmon)
    sys.add("soft_nrgmon", soft_nrgmon)

    sys.collectStats()

    nrgmon = sys[MonitorName("nrgmon")]
    dg = nrgmon.freeEnergies()[0].average()

    soft_nrgmon = sys[MonitorName("soft_nrgmon")]
    soft_dg = soft_nrgmon.freeEnergies()[0].average()

    sys_dg = sys.energy(Symbol("dE")).value()
    sys_soft_dg = sys.energy(Symbol("dE_soft")).value()

    assert_almost_equal(dg, sys_dg, 5)
    assert_almost_equal(soft_dg, sys_soft_dg, 5)
Exemple #18
0
def makeSim(system, ligand_mol, watersys):
    """Create simulation systems with and without the ligand and return those systems together
       with the moves"""

    stage1 = System("with_ligand")
    stage2 = System("without_ligand")

    if system.containsProperty("reflection center"):
        reflection_center = system.property("reflection center").toVector()[0]
        reflection_radius = float(
            str(system.property("reflection sphere radius")))

        stage1.setProperty("reflection center",
                           AtomCoords(CoordGroup(1, reflection_center)))
        stage1.setProperty("reflection sphere radius",
                           VariantProperty(reflection_radius))

        stage2.setProperty("reflection center",
                           AtomCoords(CoordGroup(1, reflection_center)))
        stage2.setProperty("reflection sphere radius",
                           VariantProperty(reflection_radius))

    # create a molecule group for fixed atoms (everything except the mobile water)
    fixed_group = MoleculeGroup("fixed")

    if MGName("fixed_molecules") in system.mgNames():
        fixed_group.add(system[MGName("fixed_molecules")])

    if MGName("mobile_solutes") in system.mgNames():
        fixed_group.add(system[MGName("mobile_solutes")])

    if MGName("protein_sidechains") in system.mgNames() or \
       MGName("protein_backbones") in system.mgNames():

        all_proteins = Molecules()

        try:
            protein_sidechains = system[MGName("protein_sidechains")]
            all_proteins.add(protein_sidechains.molecules())
        except:
            pass

        try:
            protein_backbones = system[MGName("protein_backbones")]
            all_proteins.add(protein_backbones.molecules())
        except:
            pass

        try:
            boundary_molecules = system[MGName("boundary_molecules")]
            all_proteins.add(boundary_molecules.molecules())
        except:
            pass

        for molnum in all_proteins.molNums():
            protein_mol = Molecule.join(all_proteins[molnum])
            fixed_group.add(protein_mol)

    stage1_fixed_group = MoleculeGroup(fixed_group)
    stage2_fixed_group = MoleculeGroup(fixed_group)

    stage1_fixed_group.add(ligand_mol)
    stage2_fixed_group.remove(ligand_mol)

    mobile_group = MoleculeGroup("mobile_group")
    if MGName("mobile_solvents") in system.mgNames():
        mobile_group.add(system[MGName("mobile_solvents")])

    stage1_mobile_group = MoleculeGroup(mobile_group)
    stage2_mobile_group = MoleculeGroup(mobile_group)

    # now find water molecules from the water system that can be substituted for the ligand
    watermols = findOverlappingWaters(ligand_mol, watersys)

    stage2_mobile_group.add(watermols)

    print("The number of stage 1 fixed non-solvent molecules is %d." %
          stage1_fixed_group.nMolecules())
    print("The number of stage 1 mobile solvent molecules is %d." %
          stage1_mobile_group.nMolecules())

    print("The number of stage 2 fixed non-solvent molecules is %d." %
          stage2_fixed_group.nMolecules())
    print("The number of stage 2 mobile solvent molecules is %d." %
          stage2_mobile_group.nMolecules())

    # write a PDB of all of the fixed molecules
    PDB().write(stage1_mobile_group, "stage1_mobile_atoms.pdb")
    PDB().write(stage2_mobile_group, "stage2_mobile_atoms.pdb")
    PDB().write(stage1_fixed_group, "stage1_fixed_atoms.pdb")
    PDB().write(stage2_fixed_group, "stage2_fixed_atoms.pdb")

    # create the forcefields

    if use_fast_ff.val:
        stage1_ff = InterFF("ff")
        stage2_ff = InterFF("ff")
        stage1_ff.setCLJFunction(
            CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val))
        stage2_ff.setCLJFunction(
            CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val))

        if disable_grid.val:
            stage1_ff.disableGrid()
            stage2_ff.disableGrid()
        else:
            stage1_ff.enableGrid()
            stage1_ff.setGridSpacing(grid_spacing.val)
            stage1_ff.setGridBuffer(grid_buffer.val)
            stage2_ff.enableGrid()
            stage2_ff.setGridSpacing(grid_spacing.val)
            stage2_ff.setGridBuffer(grid_buffer.val)

        stage1_ff.add(stage1_mobile_group)
        stage1_ff.setFixedAtoms(stage1_fixed_group.molecules())
        stage2_ff.add(stage2_mobile_group)
        stage2_ff.setFixedAtoms(stage2_fixed_group.molecules())

        stage1.add(stage1_ff)
        stage1.setComponent(stage1.totalComponent(),
                            stage1_ff.components().total())
        stage2.add(stage1_ff)
        stage2.setComponent(stage2.totalComponent(),
                            stage2_ff.components().total())

    else:
        # forcefield holding the energy between the mobile atoms and
        # the fixed atoms
        if disable_grid.val:
            stage1_mobile_fixed = InterGroupCLJFF("mobile-fixed")
            stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed)
            stage1_mobile_fixed = setFakeGridProperties(stage1_mobile_fixed)
            stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0))
            stage1_mobile_fixed.add(stage1_fixed_group, MGIdx(1))

            stage2_mobile_fixed = InterGroupCLJFF("mobile-fixed")
            stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed)
            stage2_mobile_fixed = setFakeGridProperties(stage2_mobile_fixed)
            stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0))
            stage2_mobile_fixed.add(stage2_fixed_group, MGIdx(1))
        else:
            stage1_mobile_fixed = GridFF2("mobile-fixed")
            stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed)
            stage1_mobile_fixed = setGridProperties(stage1_mobile_fixed)

            stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0))
            stage1_mobile_fixed.addFixedAtoms(stage1_fixed_group)

            stage2_mobile_fixed = GridFF2("mobile-fixed")
            stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed)
            stage2_mobile_fixed = setGridProperties(stage2_mobile_fixed)

            stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0))
            stage2_mobile_fixed.addFixedAtoms(stage2_fixed_group)

        # forcefield holding the energy between fixed atoms
        stage1_mobile_mobile = InterCLJFF("mobile-mobile")
        stage1_mobile_mobile = setCLJProperties(stage1_mobile_mobile)
        stage1_mobile_mobile.add(stage1_mobile_group)

        stage2_mobile_mobile = InterCLJFF("mobile-mobile")
        stage2_mobile_mobile = setCLJProperties(stage2_mobile_mobile)
        stage2_mobile_mobile.add(stage2_mobile_group)

        stage1.add(stage1_mobile_group)
        stage1.add(stage1_mobile_fixed)
        stage1.add(stage1_mobile_mobile)

        stage2.add(stage2_mobile_group)
        stage2.add(stage2_mobile_fixed)
        stage2.add(stage2_mobile_mobile)

        stage1.setComponent(
            stage1.totalComponent(),
            stage1_mobile_mobile.components().total() +
            stage1_mobile_fixed.components().total())
        stage2.setComponent(
            stage2.totalComponent(),
            stage2_mobile_mobile.components().total() +
            stage2_mobile_fixed.components().total())

    stage1.add(stage1_mobile_group)
    stage2.add(stage2_mobile_group)

    stage1.add("volume_map", VolMapMonitor(stage1_mobile_group), 1000)
    stage2.add("volume_map", VolMapMonitor(stage2_mobile_group), 1000)

    max_water_translation = 0.15 * angstroms
    max_water_rotation = 15 * degrees

    stage1_moves = WeightedMoves()

    if stage1_mobile_group.nViews() > 0:
        rb_moves = RigidBodyMC(stage1_mobile_group)
        rb_moves.setMaximumTranslation(max_water_translation)
        rb_moves.setMaximumRotation(max_water_rotation)

        if stage1.containsProperty("reflection sphere radius"):
            reflection_radius = float(
                str(stage1.property("reflection sphere radius"))) * angstroms
            reflection_center = stage1.property(
                "reflection center").toVector()[0]
            rb_moves.setReflectionSphere(reflection_center, reflection_radius)

        stage1_moves.add(rb_moves, stage1_mobile_group.nViews())

    stage2_moves = WeightedMoves()

    if stage2_mobile_group.nViews() > 0:
        rb_moves = RigidBodyMC(stage2_mobile_group)
        rb_moves.setMaximumTranslation(max_water_translation)
        rb_moves.setMaximumRotation(max_water_rotation)

        if stage2.containsProperty("reflection sphere radius"):
            reflection_radius = float(
                str(stage2.property("reflection sphere radius"))) * angstroms
            reflection_center = stage2.property(
                "reflection center").toVector()[0]
            rb_moves.setReflectionSphere(reflection_center, reflection_radius)

        stage2_moves.add(rb_moves, stage2_mobile_group.nViews())

    stage1_moves.setTemperature(temperature.val)
    stage2_moves.setTemperature(temperature.val)

    seed = random_seed.val

    if seed is None:
        seed = RanGenerator().randInt(100000, 1000000)
        print("Using generated random number seed %d" % seed)
    else:
        print("Using supplied random number seed %d" % seed)

    stage1_moves.setGenerator(RanGenerator(seed))
    stage2_moves.setGenerator(RanGenerator(seed + 7))

    return ((stage1, stage1_moves), (stage2, stage2_moves))
protoms.addParameterFile("test/io/oscillators.ff")

oscillator = protoms.parameterise(oscillator, ProtoMS.SOLUTE)

print("...parameterisation complete!")

internalff = InternalFF("InternalFF")

internalff.add(oscillator)

system = System()
system.add(internalff)

lam = Symbol("lambda")

system.setComponent(lam, 0.01)

system.setComponent(system.totalComponent(),
                    lam * internalff.components().total())

system.add("average energy", MonitorComponent(system.totalComponent()))

lambda_values = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]

replicas = Replicas(system, len(lambda_values))

replicas.setLambdaComponent(lam)

for i in range(0, len(lambda_values)):
    replicas.setLambdaValue(i, lambda_values[i])
# Add the protein
cljff.add(protein)

# Now also add a forcefield to calculate the intramolecular
# bond, angle and dihedral energy of the protein
intraff = InternalFF("intraff")

# Add the protein
intraff.add(protein)

# Add the forcefields to the system
system.add(cljff)
system.add(intraff)

# Set the expression used to calculate the total energy
# of the system
system.setComponent( system.totalComponent(),
                     cljff.components().total() + 
                     intraff.components().total() )

# Tell the system about the periodic box
system.setProperty("space", space)
system.add( SpaceWrapper(Vector(0), protein) )
system.applyConstraints()

# Save a binary representation of the system
# to the file "protein.s3"
import Sire.Stream
Sire.Stream.save( system, "protein.s3" )
Exemple #21
0
protoms.addParameterFile( "test/io/oscillators.ff" )

oscillator = protoms.parameterise(oscillator, ProtoMS.SOLUTE)

print("...parameterisation complete!")

internalff = InternalFF("InternalFF")

internalff.add( oscillator )

system = System()
system.add( internalff )

lam = Symbol("lambda")

system.setComponent(lam, 0.01)

system.setComponent(system.totalComponent(), lam * internalff.components().total())

system.add( "average energy", MonitorComponent(system.totalComponent()) )

lambda_values = [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 ]

replicas = Replicas(system, len(lambda_values))

replicas.setLambdaComponent(lam)

for i in range(0,len(lambda_values)):
    replicas.setLambdaValue(i, lambda_values[i])

zmatmove = ZMatMove( internalff.groups()[0] )
Exemple #22
0
# Sire performs simulations on simulation System objects.
# A System groups together all of the molecules, forcefields etc.
# into a single unit
system = System()
system.add(cljff)

# Here we create the equation used to calculate the total energy of the
# system. We define a symbol, lambda, which we use here to scale up and
# down the coulomb component of cljff
lam = Symbol("lambda")
total_nrg = cljff.components().lj() + lam * cljff.components().coulomb()

# Here we tell the system to use our equation to calculate the total
# energy, and we set the value of lambda to 0.5
system.setComponent(system.totalComponent(), total_nrg)
system.setConstant(lam, 0.5)

# Now we create a MoleculeGroup that groups together all of the
# molecules to be moved
mobile_mols = MoleculeGroup("mobile_molecules")
mobile_mols.add(first_water)
mobile_mols.add(second_water)

# We add the molecule group to the system
system.add(mobile_mols)

# We create a periodic boundaries space, and give it to the system
space = PeriodicBox(Vector(5, 5, 5))
system.setProperty("space", space)