Exemple #1
0
def test_grid_sim(verbose = False):
    oldsys = System()
    newsys = System()

    oldsys.add(cluster)
    oldsys.add(old_clusterff)
    oldsys.add(old_fixedff)

    newsys.add(cluster)
    newsys.add(new_clusterff)

    t = QElapsedTimer()
    t.start()
    old_total = oldsys.energy().value()
    oldns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    newns = t.nsecsElapsed()

    ff = newsys[FFName("new_clusterff")]
    print(ff.grid())

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()

    new_cnrg = newsys.energy( new_clusterff.components().coulomb() ).value()
    new_ljnrg = newsys.energy( new_clusterff.components().lj() ).value()

    if verbose:
        print("OLD:  %s  %s  %s  %s  : %s ms" % (old_total,old_cnrg+old_ljnrg,old_cnrg,old_ljnrg,
                                             0.000001*oldns))
        print("NEW:  %s  %s  %s  %s  : %s ms" % (new_total,new_cnrg+new_ljnrg,new_cnrg,new_ljnrg,
                                             0.000001*newns))

    moves = RigidBodyMC(cluster)                    
    moves.enableOptimisedMoves()
    moves.setReflectionSphere( reflect_sphere_center, reflect_sphere_radius )
    moves.setGenerator( RanGenerator( 42 ) )
    
    t.start()
    moves.move(oldsys, 1000, False)
    move_oldns = t.nsecsElapsed()

    moves.setGenerator( RanGenerator( 42 ) )

    t.start()
    moves.move(newsys, 1000, False)
    move_newns = t.nsecsElapsed()

    t.start()
    old_total = oldsys.energy().value()
    old_ns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    new_ns = t.nsecsElapsed()

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()

    new_cnrg = newsys.energy( new_clusterff.components().coulomb() ).value()
    new_ljnrg = newsys.energy( new_clusterff.components().lj() ).value()

    if verbose:
        print("\nMoves: %s ms vs. %s ms" % (0.000001*move_oldns, 0.000001*move_newns))
        print("OLD SYS:  %s  %s  %s  %s  : %s ms" % (old_total,old_cnrg+old_ljnrg,old_cnrg,old_ljnrg,
                                                 0.000001*old_ns))
        print("NEW SYS:  %s  %s  %s  %s  : %s ms" % (new_total,new_cnrg+new_ljnrg,new_cnrg,new_ljnrg,
                                                 0.000001*new_ns))

    newsys.mustNowRecalculateFromScratch()
    oldsys.mustNowRecalculateFromScratch()

    t.start()
    old_total = oldsys.energy().value()
    old_ns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    new_ns = t.nsecsElapsed()

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()
    
    new_cnrg = newsys.energy( new_clusterff.components().coulomb() ).value()
    new_ljnrg = newsys.energy( new_clusterff.components().lj() ).value()

    if verbose:
        print("\nRecalculate energy")
        print("OLD SYS:  %s  %s  %s  %s  : %s ms" % (old_total,old_cnrg+old_ljnrg,old_cnrg,old_ljnrg,
                                                 0.000001*old_ns))
        print("NEW SYS:  %s  %s  %s  %s  : %s ms" % (new_total,new_cnrg+new_ljnrg,new_cnrg,new_ljnrg,
                                                 0.000001*new_ns))
Exemple #2
0
    PrefSampler(solute.moleculeAt(0), solvent, 200 * angstrom2))
solvent_move.setMaximumTranslation(0.2 * angstrom)
solvent_move.setMaximumRotation(5 * degrees)

solute_move = RigidBodyMC(solute)
solute_move.setMaximumTranslation(0.2 * angstrom)
solute_move.setMaximumRotation(5 * degrees)

moves = WeightedMoves()
moves.add(solvent_move, 100)
moves.add(solute_move, 1)

for i in range(1, 11):
    system = moves.move(system, 5000, False)
    #system = moves.move(system, 50, False)
    print("Step %d of 10: Energy = %s" % (i, system.energy()))

    PDB().write(system.molecules(), "test_equil_%0004d.pdb" % i)

print("Equilibration complete")

print("Adding energy monitors...")

identity_points = []

for atom in identity_atoms:
    identity_points.append(AtomPoint(
        solute.moleculeAt(0).atom(AtomName(atom))))

idassigner = IDAssigner(identity_points, solvent)
Exemple #3
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 #4
0
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)

moves = SameMoves(rbmc)

PDB().write(grid_system2.molecules(), "test0000.pdb")

t = QTime()

for i in range(1,11):
    print("Moving the system...")
Exemple #5
0
protoms_dir = os.getenv("HOME") + "/Work/ProtoMS"

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

protoms.addParameterFile("%s/parameter/amber99.ff" % protoms_dir )
protoms.addParameterFile("%s/parameter/gaff.ff" % protoms_dir )
protoms.addParameterFile("test/ff/sb2.ff")

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

qmff = QMFF("MopacFF")
mopac = Mopac()
qmff.setQuantumProgram( mopac )

qmff.add(sb2)

system = System()

system.add(qmff)

zmat_move = ZMatMove(qmff[MGIdx(0)])

moves = SameMoves(zmat_move)

import Sire.Stream
Sire.Stream.save( (system,moves), "test/Squire/mopacsim.s3" )

print("Energy before == %f kcal mol-1" % system.energy().to(kcal_per_mol))
system = moves.move(system)
print("Energy after == %f kcal mol-1" % system.energy().to(kcal_per_mol))
    forcefield.add(protein)
    system.add(forcefield)


def printEnergies(nrgs):
    keys = list(nrgs.keys())
    keys.sort()

    for key in keys:
        print("%25s : %12.8f" % (key, nrgs[key]))


system.setProperty("switchingFunction",
                   HarmonicSwitchingFunction(10 * angstrom, 9.5 * angstrom))

printEnergies(system.energies())

print("\nEnergy with respect to cutoff length\n")
print("  Distance   Group    Shifted    ReactionField  ")

for i in range(10, 501, 5):
    x = i * 0.1

    switchfunc = HarmonicSwitchingFunction(x * angstrom, (x - 0.5) * angstrom)
    system.setProperty("switchingFunction", switchfunc)

    print(
        "%12.8f  %12.8f  %12.8f  %12.8f" %
        (x, system.energy(group_coul).value(),
         system.energy(shift_coul).value(), system.energy(field_coul).value()))
def test_moves(verbose = False):
    newsys = System()
    oldsys = System()
    optsys = System()
    parsys = System()

    res = MoleculeGroup("residues")
    protein = mols[ MolWithResID("ALA") ].molecule()

    for residue in protein.residues():
        res.add(residue)

    newsys.add(newff)
    oldsys.add(oldff)
    optsys.add(newff)
    parsys.add(parff)

    newsys.add(res)
    oldsys.add(res)
    optsys.add(res)
    parsys.add(res)

    moves = RigidBodyMC(res)
    moves.disableOptimisedMoves()

    moves.setMaximumTranslation( 0.2 * angstrom )
    moves.setMaximumRotation( 0.5 * degrees )

    opt_moves = RigidBodyMC(res)
    opt_moves.enableOptimisedMoves()

    opt_moves.setMaximumTranslation( 0.2 * angstrom )
    opt_moves.setMaximumRotation( 0.5 * degrees )

    t = QElapsedTimer()

    if verbose:
        print("Calculating initial energy...")

    t.start()
    oldnrg = oldsys.energy().value()
    oldns = t.nsecsElapsed()

    t.start()
    newnrg = newsys.energy().value()
    newns = t.nsecsElapsed()

    t.start()
    optnrg = optsys.energy().value()
    optns = t.nsecsElapsed()

    t.start()
    parnrg = parsys.energy().value()
    parns = t.nsecsElapsed()

    if verbose:
        print("\nTIMES: old = %s ms, new = %s ms, opt = %s ms, par = %s ms" % \
                        (oldns*0.000001,newns*0.000001,optns*0.000001,parns*0.000001))
        print("\nENERGIES: old = %s, new = %s, opt = %s, par = %s" % \
                        (oldnrg,newnrg,optnrg,parnrg))

    assert_almost_equal( oldnrg, newnrg, 0.5 )
    assert_almost_equal( optnrg, newnrg, 0.1 )
    assert_almost_equal( parnrg, newnrg, 0.1 )

    if verbose:
        print("\nPerforming simulation...")

    moves.clearStatistics()
    moves.setGenerator( RanGenerator(42) )
    t.start()
    moves.move(oldsys, nmoves, False)
    oldns = t.nsecsElapsed()
    old_naccept = moves.nAccepted()
    old_nreject = moves.nRejected()

    oldcnrg = oldsys.energy( oldff.components().coulomb() ).value()
    oldljnrg = oldsys.energy( oldff.components().lj() ).value()

    oldsys.mustNowRecalculateFromScratch()    

    check_oldcnrg = oldsys.energy( oldff.components().coulomb() ).value()
    check_oldljnrg = oldsys.energy( oldff.components().lj() ).value()

    moves.clearStatistics()
    moves.setGenerator( RanGenerator(42) )
    t.start()
    moves.move(newsys, nmoves, False)
    newns = t.nsecsElapsed()
    new_naccept = moves.nAccepted()
    new_nreject = moves.nRejected()

    newcnrg = newsys.energy( newff.components().coulomb() ).value()
    newljnrg = newsys.energy( newff.components().lj() ).value()

    newsys.mustNowRecalculateFromScratch()    

    check_newcnrg = newsys.energy( newff.components().coulomb() ).value()
    check_newljnrg = newsys.energy( newff.components().lj() ).value()

    opt_moves.clearStatistics()
    opt_moves.setGenerator( RanGenerator(42) )
    t.start()
    opt_moves.move(optsys, nmoves, False)
    optns = t.nsecsElapsed()
    opt_naccept = moves.nAccepted()
    opt_nreject = moves.nRejected()

    optcnrg = optsys.energy( newff.components().coulomb() ).value()
    optljnrg = optsys.energy( newff.components().lj() ).value()

    optsys.mustNowRecalculateFromScratch()

    check_optcnrg = optsys.energy( newff.components().coulomb() ).value()
    check_optljnrg = optsys.energy( newff.components().lj() ).value()

    opt_moves.clearStatistics()
    opt_moves.setGenerator( RanGenerator(42) )
    t.start()
    opt_moves.move(parsys, nmoves, False)
    parns = t.nsecsElapsed()
    par_naccept = moves.nAccepted()
    par_nreject = moves.nRejected()

    parcnrg = parsys.energy( parff.components().coulomb() ).value()
    parljnrg = parsys.energy( parff.components().lj() ).value()

    parsys.mustNowRecalculateFromScratch()    

    check_parcnrg = parsys.energy( parff.components().coulomb() ).value()
    check_parljnrg = parsys.energy( parff.components().lj() ).value()

    if verbose:
        print("\nTIMES: old = %s ms, new = %s ms, opt = %s ms, par = %s ms" % \
                        (oldns*0.000001,newns*0.000001,optns*0.000001,parns*0.000001))

        print("\nNACCEPT: old = %s, new = %s, opt = %s, par = %s" % \
                        (old_naccept,new_naccept,opt_naccept,par_naccept))

        print("NREJECT: old = %s, new = %s, opt = %s, par = %s" % \
                        (old_nreject,new_nreject,opt_nreject,par_nreject))

        print("\nTotal energy")
        print("OLD FF :  %s  %s  %s" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg))
        print("NEW FF :  %s  %s  %s" % (newcnrg+newljnrg,newcnrg,newljnrg))
        print("OPT FF :  %s  %s  %s" % (optcnrg+optljnrg,optcnrg,optljnrg))
        print("PAR FF :  %s  %s  %s" % (parcnrg+parljnrg,parcnrg,parljnrg))

        print("\nCheck energy")
        print("OLD FF :  %s  %s  %s" % (check_oldcnrg+check_oldljnrg,check_oldcnrg,check_oldljnrg))
        print("NEW FF :  %s  %s  %s" % (check_newcnrg+check_newljnrg,check_newcnrg,check_newljnrg))
        print("OPT FF :  %s  %s  %s" % (check_optcnrg+check_optljnrg,check_optcnrg,check_optljnrg))
        print("PAR FF :  %s  %s  %s" % (check_parcnrg+check_parljnrg,check_parcnrg,check_parljnrg))

    assert_equal( new_naccept, old_naccept )
    assert_equal( new_nreject, old_nreject )
    assert_equal( opt_naccept, old_naccept )
    assert_equal( opt_nreject, old_nreject )
    assert_equal( par_naccept, old_naccept )
    assert_equal( par_nreject, old_nreject )

    assert_almost_equal( oldcnrg, check_oldcnrg, 0.1 )
    assert_almost_equal( oldljnrg, check_oldljnrg, 0.1 )
    assert_almost_equal( newcnrg, check_newcnrg, 0.1 )
    assert_almost_equal( newljnrg, check_newljnrg, 0.1 )
    assert_almost_equal( optcnrg, check_optcnrg, 0.1 )
    assert_almost_equal( optljnrg, check_optljnrg, 0.1 )
    assert_almost_equal( parcnrg, check_parcnrg, 0.1 )
    assert_almost_equal( parljnrg, check_parljnrg, 0.1 )
    assert_almost_equal( newcnrg, oldcnrg, 0.5 )
    assert_almost_equal( newljnrg, oldljnrg, 0.5 )
    assert_almost_equal( optcnrg, newcnrg, 0.1 )
    assert_almost_equal( optljnrg, newljnrg, 0.1 )
    assert_almost_equal( parcnrg, newcnrg, 0.1 )
    assert_almost_equal( parljnrg, newljnrg, 0.1 )
    mol = mols.moleculeAt(i).molecule()

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

    cljff.add(mol)
    mols.update(mol)

system = System()

system.add(cljff)

print("System energy equals...")
print(system.energy())

group0 = MoleculeGroup("group0")
group1 = MoleculeGroup("group1")

group0.add( mols.moleculeAt(100) )
group0.add( mols.moleculeAt(101) )

group1.add( mols.moleculeAt(102) )
group1.add( mols.moleculeAt(103) )
group1.add( mols.moleculeAt(104) )

cljff2 = InterGroupCLJFF("group_energy")
cljff2.add( group0, MGIdx(0) )
cljff2.add( group1, MGIdx(1) )
cljff2.setSpace(vol)
Exemple #9
0
        cljff_a.add(mol)
        cljff_a_b.add( mol, MGIdx(0) )
    else:
        cljff_b.add(mol)
        cljff_a_b.add( mol, MGIdx(1) )

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

system = System()
system.add(solvent)

system.add(cljff)

t.start()
print("Initial energy = %s" % system.energy())
print("(took %d ms)" % t.elapsed())
print(system.property("space"))
print(system.property("switchingFunction"))

system2 = System()
system2.add(solvent)

system2.add(cljff_a)
system2.add(cljff_b)
system2.add(cljff_a_b)

print(system.groupNumbers())
print(system.groupNames())
print(system.energies())
print(system2.groupNumbers())
Exemple #10
0
print(bonds.potentials())
print(angles.potentials())
print(dihedrals.potentials())

#intraff = InternalFF("intraff")
intraclj = IntraCLJFF("intraclj")

#intraff.add(ethane)
intraclj.add(ethane)

solute = MoleculeGroup("solute", ethane)
solute.add(ethane)

system = System()
#system.add(intraff)
system.add(intraclj)
system.add(solute)

md = MolecularDynamics(solute, VelocityVerlet())
#                     {"velocity generator" : MaxwellBoltzmann(25*celsius)})

md.setTimeStep(1 * femtosecond)

PDB().write(system.molecules(), "test0000.pdb")

for i in range(1, 250):
    md.move(system, 1)
    print(system.energy(), md.kineticEnergy(),
          (system.energy() + md.kineticEnergy()))
    PDB().write(system.molecules(), "test%0004d.pdb" % i)
Exemple #11
0
system = System()

system.add(cljff)
system.add(waters)

# constrain the identities of the first three waters
points = []

for i in range(0,3):
   points.append( waters.moleculeAt(i).molecule().evaluate().center() )

system.add( IdentityConstraint(points, waters) )

print("Calculating the starting energy... (should be -16364.5 kcal mol-1)")
print("...Initial energy = %s" % system.energy())

rbmc = RigidBodyMC(waters)
rbmc.setMaximumTranslation( 0.15*angstrom )
rbmc.setMaximumRotation( 15*degrees )
rbmc.setTemperature( 25*celsius )

#volmc = VolumeMove(waters)
#volmc.setMaximumVolumeChange( 0.1 * waters.nMolecules() * angstrom3 )
#volmc.setPressure( 1*atm )

moves = WeightedMoves()
#moves.add( volmc, 1 )
moves.add( rbmc, waters.nMolecules() )

# The simulation is now ready to run - create an output directory
Exemple #12
0
cljff = InterCLJFF("salt-salt")
cljff.add(salt)
internalff.add(salt)

system = System()
system.add(salt)
system.add(cljff)
system.add(internalff)

system.setProperty("space", PeriodicBox(Vector(20, 20, 20)))

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

t.start()
print("Initial energy = %s" % system.energy())
print("(took %d ms)" % t.elapsed())

mdmove = MolecularDynamics(
    salt, VelocityVerlet(),
    {"velocity generator": MaxwellBoltzmann(25 * celsius)})

mdmove = MolecularDynamics(salt, DLMRigidBody())

mdmove.setTimeStep(1 * femtosecond)
do_mc = False

intra_mcmove = InternalMove(salt)
inter_mcmove = RigidBodyMC(salt)

mcmove = WeightedMoves()
Exemple #13
0
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)

moves = SameMoves(rbmc)

PDB().write(grid_system.molecules(), "test0000.pdb")

t = QTime()

for i in range(1,11):
    print("Moving the system...")
def printMols( mols, molrange ):

   for i in molrange:
       mol_i = mols[ MolIdx(i) ]
       print(i, mol_i, mol_i.evaluate().center())

print("\nHERE ARE MOLECULES 0, 1, 10 and 20")
printMols( cljff, [0,1,10,20] )

system = System()

system.add(cljff)

t.start()
nrg = system.energy()
ms = t.elapsed()

print("\nEnergy = %f kcal mol-1 - took %d ms" % (nrg.to(kcal_per_mol), ms))

def testConstraint(points, system):

    print("Creating the identity constraint...")
    t.start()

    if len(points) == 0:
        idcons = IdentityConstraint( system[MGIdx(0)] )
    else:
        idcons = IdentityConstraint( points, system[MGIdx(0)] )

    ms = t.elapsed()
Exemple #15
0
rb_moves.setMaximumTranslation(max_translate)
rb_moves.setTemperature(temperature)

# create volume moves to change the box size
vol_moves = VolumeMove(mols)
vol_moves.setMaximumVolumeChange(mols.nMolecules() * 0.1 * angstrom3)
vol_moves.setTemperature(temperature)
vol_moves.setPressure(pressure)

# group these two moves together
moves = WeightedMoves()
moves.add(rb_moves, mols.nMolecules())
moves.add(vol_moves, 1)

# print the initial energy and coordinates
print("0:   %s" % system.energy())
PDB().write(system.molecules(), "output000000.pdb")

# now run the simulation in blocks of 1000 moves
nmoves = 0
while nmoves < num_moves:
    system = moves.move(system, 1000, False)
    nmoves += 1000

    # print out the energy and coordinates every 1000 moves
    print("%s  %s" % (nmoves, system.energy()))
    print(moves)

    PDB().write(system.molecules(), "output%000006d.pdb" % nmoves)

print("Complete!")
Exemple #16
0
def test_system(verbose=False):

    cljff = InterCLJFF()

    mincoords = Vector(-18.3854, -18.66855, -18.4445)
    maxcoords = Vector(18.3854, 18.66855, 18.4445)

    vol = PeriodicBox(mincoords, maxcoords)

    cljff.setSpace(vol)

    mols = PDB().read("../io/water.pdb")

    if verbose:
        print("Read in %d molecules!" % mols.nMolecules())

    i = 0

    mol = mols.moleculeAt(0).molecule()

    mol = mol.edit().atom( AtomName("O00") ) \
                        .setProperty("LJ", LJParameter(3.15363*angstrom,  \
                                                   0.1550*kcal_per_mol)).molecule() \
                    .atom( AtomName("H01") ) \
                        .setProperty("charge", 0.520 * mod_electron).molecule() \
                    .atom( AtomName("H02") ) \
                        .setProperty("charge", 0.520 * mod_electron).molecule() \
                    .atom( AtomName("M03") ) \
                        .setProperty("charge", -1.04 * mod_electron).molecule() \
             .commit()

    charges = mol.property("charge")
    ljs = mol.property("LJ")

    cljff.add(mol)

    for i in range(1, mols.nMolecules()):
        mol = mols.moleculeAt(i).molecule()

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

        cljff.add(mol)

    system = System()

    system.add(cljff)

    nrg = system.energy()

    if verbose:
        print("System energy = %s" % (nrg))

    copy_system = System(system)

    nrg2 = copy_system.energy()

    if verbose:
        print("Copy energy: %s (should be %s)" % (nrg2, nrg))

    assert_almost_equal(nrg.value(), nrg2.value(), 5)

    copy_system.mustNowRecalculateFromScratch()
    nrg3 = copy_system.energy()

    if verbose:
        print("Copy energy: %s (should be %s)" % (nrg2, nrg))

    assert_almost_equal(nrg.value(), nrg3.value(), 5)
Exemple #17
0
for i in range(1, 7):
    mol = mols.moleculeAt(i).molecule()

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

    solvent.add(mol)
    cljff.add(mol)

system = System()
system.add(solvent)
system.add(cljff)

print(system.energy())

rbmove = MolecularDynamics(solvent, DLMRigidBody(), 1 * femtosecond)

#rbmove.setEnergyComponent( cljff.components().coulomb() )

PDB().write(system.molecules(), "test0000.pdb")

for i in range(1, 1000):
    rbmove.move(system, 10)
    print(i, system.energy())
    print(rbmove.kineticEnergy(), (system.energy() + rbmove.kineticEnergy()))

    PDB().write(system.molecules(), "test%0004d.pdb" % i)
Exemple #18
0
def estimateDG(topfile=None,crdfile=None,pertfile=None,
               trajfile=None,librarypath=None):
    """
    This subroutine loads a trajectory for an alchemical state, and a list of
    ligand molecules
    For each frame of the trajectory
        for each perturbed ligand
          Align the perturbed ligand onto reference ligand.
          Generate K poses
          Accumulate exp energy difference
    Estimate (w bootstrapping) free energy difference & uncertainties
    """
    print ("HELLO ESTIMATE DG")
    # Setup system describing alchemical state
    amber = Amber()
    (molecules, space) = amber.readCrdTop(crdfile, topfile)
    morphfile = Parameter("morphfile",pertfile,""".""")
    system = createSystemFreeEnergy(molecules, morphfile=morphfile)
    cutoff_type = Parameter(".","cutoffperiodic",""".""")
    cutoff_dist = Parameter(".",10*angstrom,""".""")
    rf_dielectric = Parameter(".",82.0,""".""")
    shift_delta = Parameter(".",2.0,""".""")
    coulomb_power = Parameter(".",0,""".""")
    combining_rules = Parameter(".","arithmetic",""".""")
    lambda_val = Parameter(".",0.0,""".""")
    system = setupForceFieldsFreeEnergy(system, space, cutoff_type=cutoff_type,
                                        cutoff_dist=cutoff_dist,
                                        rf_dielectric=rf_dielectric,
                                        shift_delta=shift_delta,
                                        coulomb_power=coulomb_power,
                                        combining_rules=combining_rules,
                                        lambda_val=lambda_val)
    # Load ligands library
    # FIX ME ! Don't include ligands that have already been simulated !
    library = loadLibrary(librarypath)
    library_deltaenergies = {}
    # library_deltaenergies contain the list of computed energy differences
    for ligand in library:
        library_deltaenergies[ligand] = []
    #import pdb; pdb.set_trace()
    # Now scan trajectory
    start_frame = 1
    end_frame = 3
    step_frame = 1

    trajfile = Parameter(".",trajfile,""".""")
    mdtraj_trajfile = mdtraj.open(trajfile.val,'r')
    nframes = len(mdtraj_trajfile)
    if end_frame > (nframes - 1):
        end_frame = nframes - 1
    mdtraj_trajfile.seek(start_frame)
    current_frame = start_frame

    energies = {}
    for (ID, ligand) in library:
        energies[ID] = []
    while (current_frame <= end_frame):
        print ("#Processing frame %s " % current_frame)
        frames_xyz, cell_lengths, cell_angles = mdtraj_trajfile.read(n_frames=1)
        system = updateSystemfromTraj(system, frames_xyz, cell_lengths, cell_angles)
        ref_ligand = system[MGName("solutes")].molecules().first().molecule()
        ref_nrg = system.energy()
        print (ref_nrg)
        for (ID, ligand) in library:
            # Align ligand onto reference ligand
            mapping = AtomMCSMatcher(1*second).match(ref_ligand, PropertyMap(), ligand, PropertyMap())
            mapper = AtomResultMatcher(mapping)
            # This does a RB alignment
            # TODO) Explore optimised alignment codes
            # For instance could construct aligned ligand by reusing MCSS coordinates
            # and completing topology for variable part using BAT internal coordinates
            # Also, better otherwise never get intramolecular energy variations !
            # Basic test...SAME LIGAND should give 0 energy difference ! 
            # FIXME) Return multiple coordinates and update system in each instance
            aligned_ligand = ligand.move().align(ref_ligand, AtomMatchInverter(mapper))
            #print (ref_ligand.property("coordinates").toVector())
            #print ("####")
            #print (aligned_ligand.property("coordinates").toVector())
            # FIXME) Optimise for speed
            new_system = System()
            new_space = system.property("space")
            new_system.add( system[MGName("solvent")] )
            sols = MoleculeGroup("solutes")
            solref = MoleculeGroup("solute_ref")
            solhard = MoleculeGroup("solute_ref_hard")
            soltodummy = MoleculeGroup("solute_ref_todummy")
            solfromdummy = MoleculeGroup("solute_ref_fromdummy")
            sols.add(aligned_ligand)
            solref.add(aligned_ligand)
            solhard.add(aligned_ligand)
            new_system.add(sols)
            new_system.add(solref)
            new_system.add(solhard)
            new_system.add(soltodummy)
            new_system.add(solfromdummy)
            #print ("###")
            # DONE) Optimise for speed, only doing ligand energies
            #print (new_system[MGName("solutes")].first().molecule().property("coordinates").toVector())
            new_system = setupForceFieldsFreeEnergy(new_system, new_space, cutoff_type=cutoff_type,
                                        cutoff_dist=cutoff_dist,
                                        rf_dielectric=rf_dielectric,
                                        shift_delta=shift_delta,
                                        coulomb_power=coulomb_power,
                                        combining_rules=combining_rules,
                                        lambda_val=lambda_val)
            new_nrg = new_system.energy()
            print (new_nrg)
            energies[ID].append( new_nrg - ref_nrg )
            # for each conformation generated
            #     consider further optimisation (rapid MC --> if loaded flex files?)
            #     update 'perturbed' group with aligned ligand coordinates
            #     compute 'perturbed' energy
            #     accumulate 'perturbed' - reference
        #import pdb; pdb.set_trace()
        current_frame += step_frame
    import pdb; pdb.set_trace()
    # Now convert accumulated data int

    return 0
Exemple #19
0
print(bonds.potentials())
print(angles.potentials())
print(dihedrals.potentials())

#intraff = InternalFF("intraff")
intraclj = IntraCLJFF("intraclj")

#intraff.add(ethane)
intraclj.add(ethane)

solute = MoleculeGroup("solute", ethane)
solute.add(ethane)

system = System()
#system.add(intraff)
system.add(intraclj)
system.add(solute)

md = MolecularDynamics(solute, VelocityVerlet()) 
  #                     {"velocity generator" : MaxwellBoltzmann(25*celsius)})

md.setTimeStep(1*femtosecond)

PDB().write(system.molecules(), "test0000.pdb")

for i in range(1,250):
    md.move(system, 1)
    print(system.energy(), md.kineticEnergy(), (system.energy()+md.kineticEnergy()))
    PDB().write(system.molecules(), "test%0004d.pdb" % i)
Exemple #20
0
    mol = mols.moleculeAt(i).molecule()

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

    cljff.add(mol)
    mols.update(mol)

system = System()

system.add(cljff)

print("System energy equals...")
print(system.energy())

group0 = MoleculeGroup("group0")
group1 = MoleculeGroup("group1")

group0.add(mols.moleculeAt(100))
group0.add(mols.moleculeAt(101))

group1.add(mols.moleculeAt(102))
group1.add(mols.moleculeAt(103))
group1.add(mols.moleculeAt(104))

cljff2 = InterGroupCLJFF("group_energy")
cljff2.add(group0, MGIdx(0))
cljff2.add(group1, MGIdx(1))
cljff2.setSpace(vol)
Exemple #21
0
    print((header.systemInfo()))

    c2 = Sire.Stream.load(data)

    ms = t.elapsed()
  
    print(("Reading the data took %d ms" % ms))
    print(c)
    print(c2)

testStream(system)

data = Sire.Stream.save(system)

print("Probing the system...")
print((system.energy()))
print((system.energies()))

system = Sire.Stream.load(data)

print((system.energy()))
print((system.energies()))

print("\nGetting data info...")

t.start()
Sire.Stream.save( system, "test/SireStream/tmp_testdata.sire" )
ms = t.elapsed()

print(("Saving a system to a file took %d ms" % ms))
for i in range(0, len(lambda_values)):
    replicas.setLambdaValue(i, lambda_values[i])

zmatmove = ZMatMove(internalff.groups()[0])
zmatmove.setTemperature(298 * kelvin)

nsubmoves = 1000

replicas.setSubMoves(SameMoves(zmatmove))
replicas.setNSubMoves(nsubmoves)

# Average energy should be 1/2 kT
theo_nrg = 0.5 * gasr * 298

print("Running a simulation - initial energy = %f kcal mol-1" %
      system.energy().to(kcal_per_mol))

repexmove = RepExMove()

lambda_trajectory = []

i = -1


def printInfo(replicas):

    lamtraj = replicas.lambdaTrajectory()
    lambda_trajectory.append(lamtraj)

    ids = replicas.replicaIDs()
Exemple #23
0
def test_sim(verbose = False):

    oldsys = System()
    newsys = System()
    parsys = System()

    oldsys.add(mols)
    newsys.add(mols)
    parsys.add(mols)

    oldsys.add(newff)
    newsys.add(newff)
    parsys.add(parff)

    t = QElapsedTimer()

    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()
    parsys.mustNowRecalculateFromScratch()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()

    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    t.start()
    nrgs = parsys.energies()
    parns = t.nsecsElapsed()

    oldcnrg = oldsys.energy( newff.components().coulomb() ).value()
    oldljnrg = oldsys.energy( newff.components().lj() ).value()

    newcnrg = newsys.energy( newff.components().coulomb() ).value()
    newljnrg = newsys.energy( newff.components().lj() ).value()

    parcnrg = parsys.energy( parff.components().coulomb() ).value()
    parljnrg = parsys.energy( parff.components().lj() ).value()

    if verbose:
        print("\nStarting energy")
        print("OLD SYS:  %s  %s  %s  : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg,
                                                 0.000001*oldns))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg,
                                                 0.000001*newns))
        print("PAR SYS:  %s  %s  %s  : %s ms" % (parcnrg+parljnrg,parcnrg,parljnrg,
                                                 0.000001*parns))

    assert_almost_equal( oldcnrg, newcnrg )
    assert_almost_equal( oldljnrg, newljnrg )

    assert_almost_equal( parcnrg, newcnrg )
    assert_almost_equal( parljnrg, newljnrg )

    moves = RigidBodyMC(mols)
    moves.disableOptimisedMoves()
    moves.setGenerator( RanGenerator( 42 ) )

    optmoves = RigidBodyMC(mols)
    optmoves.enableOptimisedMoves()
    optmoves.setGenerator( RanGenerator( 42 ) )

    parmoves = RigidBodyMC(mols)
    parmoves.enableOptimisedMoves()
    parmoves.setGenerator( RanGenerator( 42 ) )

    t.start()
    moves.move(oldsys, nmoves, False)
    move_oldns = t.nsecsElapsed()

    old_naccepted = moves.nAccepted()
    old_nrejected = moves.nRejected()

    t.start()
    optmoves.move(newsys, nmoves, False)
    move_newns = t.nsecsElapsed()

    new_naccepted = optmoves.nAccepted()
    new_nrejected = optmoves.nRejected()

    t.start()
    parmoves.move(parsys, nmoves, False)
    move_parns = t.nsecsElapsed()

    par_naccepted = parmoves.nAccepted()
    par_nrejected = parmoves.nRejected()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()
    
    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()
    
    t.start()
    nrgs = parsys.energies()
    parns = t.nsecsElapsed()

    oldcnrg = oldsys.energy( newff.components().coulomb() ).value()
    oldljnrg = oldsys.energy( newff.components().lj() ).value()
    
    newcnrg = newsys.energy( newff.components().coulomb() ).value()
    newljnrg = newsys.energy( newff.components().lj() ).value()
    
    parcnrg = parsys.energy( parff.components().coulomb() ).value()
    parljnrg = parsys.energy( parff.components().lj() ).value()

    if verbose:
        print("\nMoves: %s ms vs. %s ms vs. %s ms" % (0.000001*move_oldns, 0.000001*move_newns, 0.000001*move_parns))
        print("OLD SYS:  %s  %s  %s  : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg,
                                                 0.000001*oldns))
        print("nAccepted() = %s, nRejected() = %s" % (old_naccepted, old_nrejected))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg,
                                                 0.000001*newns))
        print("nAccepted() = %s, nRejected() = %s" % (new_naccepted, new_nrejected))
        print("PAR SYS:  %s  %s  %s  : %s ms" % (parcnrg+parljnrg,parcnrg,parljnrg,
                                                 0.000001*parns))
        print("nAccepted() = %s, nRejected() = %s" % (par_naccepted, par_nrejected))
    
    assert_almost_equal( old_naccepted, new_naccepted )
    assert_almost_equal( old_nrejected, new_nrejected )
    assert_almost_equal( oldcnrg, newcnrg )
    assert_almost_equal( oldljnrg, newljnrg )

    assert_almost_equal( par_naccepted, new_naccepted )
    assert_almost_equal( par_nrejected, new_nrejected )
    assert_almost_equal( parcnrg, newcnrg )
    assert_almost_equal( parljnrg, newljnrg )

    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()
    parsys.mustNowRecalculateFromScratch()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()
    
    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    t.start()
    nrgs = parsys.energies()
    parns = t.nsecsElapsed()

    r_oldcnrg = oldsys.energy( newff.components().coulomb() ).value()
    r_oldljnrg = oldsys.energy( newff.components().lj() ).value()

    r_newcnrg = newsys.energy( newff.components().coulomb() ).value()
    r_newljnrg = newsys.energy( newff.components().lj() ).value()

    r_parcnrg = parsys.energy( parff.components().coulomb() ).value()
    r_parljnrg = parsys.energy( parff.components().lj() ).value()

    if verbose:
        print("\nRecalculated energy")
        print("OLD SYS:  %s  %s  %s  : %s ms" % (r_oldcnrg+r_oldljnrg,r_oldcnrg,r_oldljnrg,
                                                 0.000001*oldns))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (r_newcnrg+r_newljnrg,r_newcnrg,r_newljnrg,
                                                 0.000001*newns))
        print("PAR SYS:  %s  %s  %s  : %s ms" % (r_parcnrg+r_parljnrg,r_parcnrg,r_parljnrg,
                                                 0.000001*parns))

    assert_almost_equal( r_oldcnrg, r_newcnrg )
    assert_almost_equal( r_oldljnrg, r_newljnrg )
    assert_almost_equal( r_parljnrg, r_newljnrg )
Exemple #24
0
system = System()

# Add the CLJ forcefield to the system
system.add(cljff)

# Add the molecule group containing the waters to the system - we will give
# this molecule group the name 'waters' so that we can extract it from
# the system at a later point in the script
waters.setName("waters")
system.add(waters)

# Add a constraint that waters are mapped back into the periodic box
system.add(SpaceWrapper(Vector(0, 0, 0), waters))

print "Calculating the starting energy... (should be -16364.5 kcal mol-1)"
print "...Initial energy = %s" % system.energy()

# Now create the rigid body move (RigidBodyMC, from Sire.Move) that act on the waters
rbmc = RigidBodyMC(waters)

# Set the maximum amount by which to translate and rotate the water molecules
# to 0.25 A and 15 degrees (angstrom and degrees are from Sire.Units)
rbmc.setMaximumTranslation(0.25 * angstrom)
rbmc.setMaximumRotation(15 * degrees)

# Set the temperature of the moves to 25 Celsius (Celsius is from Sire.Units)
rbmc.setTemperature(25 * celsius)

# Now create the volume move (VolumeMove, from Sire.Move) that maintains a constant pressure
volmc = VolumeMove(waters)
Exemple #25
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 #26
0
def test_sim(verbose = False):

    oldsys = System()
    newsys = System()

    oldsys.add(mols)
    newsys.add(mols)

    oldsys.add(oldff)
    newsys.add(newff)

    t = QElapsedTimer()

    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()

    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    oldcnrg = oldsys.energy( oldff.components().coulomb() ).value()
    oldljnrg = oldsys.energy( oldff.components().lj() ).value()

    newcnrg = newsys.energy( newff.components().coulomb() ).value()
    newljnrg = newsys.energy( newff.components().lj() ).value()

    if verbose:
        print("\nStarting energy")
        print("OLD SYS:  %s  %s  %s  : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg,
                                                 0.000001*oldns))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg,
                                                 0.000001*newns))

    moves = RigidBodyMC(mols)
    moves.setGenerator( RanGenerator( 42 ) )
    moves.enableOptimisedMoves()

    t.start()
    moves.move(oldsys, nmoves, False)
    move_oldns = t.nsecsElapsed()

    old_naccepted = moves.nAccepted()
    old_nrejected = moves.nRejected()

    moves.setGenerator( RanGenerator( 42 ) )
    moves.clearStatistics()

    t.start()
    moves.move(newsys, nmoves, False)
    move_newns = t.nsecsElapsed()

    new_naccepted = moves.nAccepted()
    new_nrejected = moves.nRejected()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()
    
    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    oldcnrg = oldsys.energy( oldff.components().coulomb() ).value()
    oldljnrg = oldsys.energy( oldff.components().lj() ).value()
    
    newcnrg = newsys.energy( newff.components().coulomb() ).value()
    newljnrg = newsys.energy( newff.components().lj() ).value()

    if verbose:
        print("\nMoves: old %s ms vs. new %s ms" % (0.000001*move_oldns, 0.000001*move_newns))
        print("OLD SYS:  %s  %s  %s  : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg,
                                                 0.000001*oldns))
        print("nAccepted() = %s, nRejected() = %s" % (old_naccepted, old_nrejected))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg,
                                                 0.000001*newns))
        print("nAccepted() = %s, nRejected() = %s" % (new_naccepted, new_nrejected))
    
    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()
    
    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()
    
    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    r_oldcnrg = oldsys.energy( oldff.components().coulomb() ).value()
    r_oldljnrg = oldsys.energy( oldff.components().lj() ).value()

    r_newcnrg = newsys.energy( newff.components().coulomb() ).value()
    r_newljnrg = newsys.energy( newff.components().lj() ).value()

    if verbose:
        print("\nRecalculated energy")
        print("OLD SYS:  %s  %s  %s  : %s ms" % (r_oldcnrg+r_oldljnrg,r_oldcnrg,r_oldljnrg,
                                                 0.000001*oldns))
        print("NEW SYS:  %s  %s  %s  : %s ms" % (r_newcnrg+r_newljnrg,r_newcnrg,r_newljnrg,
                                                 0.000001*newns))
Exemple #27
0
def test_sim(verbose=False):

    oldsys = System()
    newsys = System()

    #oldsys.add(mols)
    #newsys.add(mols)

    oldsys.add(oldff)
    newsys.add(newff)

    t = QElapsedTimer()

    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()

    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    oldcnrg = oldsys.energy(oldff.components().coulomb()).value()
    oldljnrg = oldsys.energy(oldff.components().lj()).value()

    newcnrg = newsys.energy(newff.components().coulomb()).value()
    newljnrg = newsys.energy(newff.components().lj()).value()

    if verbose:
        print("\nStarting energy")
        print("OLD SYS:  %s  %s  %s  : %s ms" %
              (oldcnrg + oldljnrg, oldcnrg, oldljnrg, 0.000001 * oldns))
        print("NEW SYS:  %s  %s  %s  : %s ms" %
              (newcnrg + newljnrg, newcnrg, newljnrg, 0.000001 * newns))

    moves = RigidBodyMC(mols)
    moves.setGenerator(RanGenerator(42))

    t.start()
    moves.move(oldsys, nmoves, False)
    move_oldns = t.nsecsElapsed()

    old_naccepted = moves.nAccepted()
    old_nrejected = moves.nRejected()

    moves.setGenerator(RanGenerator(42))
    moves.clearStatistics()

    t.start()
    moves.move(newsys, nmoves, False)
    move_newns = t.nsecsElapsed()

    new_naccepted = moves.nAccepted()
    new_nrejected = moves.nRejected()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()

    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    oldcnrg = oldsys.energy(oldff.components().coulomb()).value()
    oldljnrg = oldsys.energy(oldff.components().lj()).value()

    newcnrg = newsys.energy(newff.components().coulomb()).value()
    newljnrg = newsys.energy(newff.components().lj()).value()

    if verbose:
        print("\nMoves: %s ms vs. %s ms" %
              (0.000001 * move_oldns, 0.000001 * move_newns))
        print("OLD SYS:  %s  %s  %s  : %s ms" %
              (oldcnrg + oldljnrg, oldcnrg, oldljnrg, 0.000001 * oldns))
        print("nAccepted() = %s, nRejected() = %s" %
              (old_naccepted, old_nrejected))
        print("NEW SYS:  %s  %s  %s  : %s ms" %
              (newcnrg + newljnrg, newcnrg, newljnrg, 0.000001 * newns))
        print("nAccepted() = %s, nRejected() = %s" %
              (new_naccepted, new_nrejected))

    oldsys.mustNowRecalculateFromScratch()
    newsys.mustNowRecalculateFromScratch()

    t.start()
    nrgs = oldsys.energies()
    oldns = t.nsecsElapsed()

    t.start()
    nrgs = newsys.energies()
    newns = t.nsecsElapsed()

    r_oldcnrg = oldsys.energy(oldff.components().coulomb()).value()
    r_oldljnrg = oldsys.energy(oldff.components().lj()).value()

    r_newcnrg = newsys.energy(newff.components().coulomb()).value()
    r_newljnrg = newsys.energy(newff.components().lj()).value()

    if verbose:
        print("\nRecalculated energy")
        print(
            "OLD SYS:  %s  %s  %s  : %s ms" %
            (r_oldcnrg + r_oldljnrg, r_oldcnrg, r_oldljnrg, 0.000001 * oldns))
        print(
            "NEW SYS:  %s  %s  %s  : %s ms" %
            (r_newcnrg + r_newljnrg, r_newcnrg, r_newljnrg, 0.000001 * newns))
Exemple #28
0
    mol = mol.edit().rename("T4P") \
                    .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)

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() + \
Exemple #29
0
def test_grid_sim(verbose=False):
    oldsys = System()
    newsys = System()

    oldsys.add(cluster)
    oldsys.add(old_clusterff)
    oldsys.add(old_fixedff)

    newsys.add(cluster)
    newsys.add(new_clusterff)

    t = QElapsedTimer()
    t.start()
    old_total = oldsys.energy().value()
    oldns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    newns = t.nsecsElapsed()

    ff = newsys[FFName("new_clusterff")]
    print(ff.grid())

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()

    new_cnrg = newsys.energy(new_clusterff.components().coulomb()).value()
    new_ljnrg = newsys.energy(new_clusterff.components().lj()).value()

    if verbose:
        print("OLD:  %s  %s  %s  %s  : %s ms" %
              (old_total, old_cnrg + old_ljnrg, old_cnrg, old_ljnrg,
               0.000001 * oldns))
        print("NEW:  %s  %s  %s  %s  : %s ms" %
              (new_total, new_cnrg + new_ljnrg, new_cnrg, new_ljnrg,
               0.000001 * newns))

    moves = RigidBodyMC(cluster)
    moves.setReflectionSphere(reflect_sphere_center, reflect_sphere_radius)
    moves.setGenerator(RanGenerator(42))

    t.start()
    moves.move(oldsys, 1000, False)
    move_oldns = t.nsecsElapsed()

    moves.setGenerator(RanGenerator(42))

    t.start()
    moves.move(newsys, 1000, False)
    move_newns = t.nsecsElapsed()

    t.start()
    old_total = oldsys.energy().value()
    old_ns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    new_ns = t.nsecsElapsed()

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()

    new_cnrg = newsys.energy(new_clusterff.components().coulomb()).value()
    new_ljnrg = newsys.energy(new_clusterff.components().lj()).value()

    if verbose:
        print("\nMoves: %s ms vs. %s ms" %
              (0.000001 * move_oldns, 0.000001 * move_newns))
        print("OLD SYS:  %s  %s  %s  %s  : %s ms" %
              (old_total, old_cnrg + old_ljnrg, old_cnrg, old_ljnrg,
               0.000001 * old_ns))
        print("NEW SYS:  %s  %s  %s  %s  : %s ms" %
              (new_total, new_cnrg + new_ljnrg, new_cnrg, new_ljnrg,
               0.000001 * new_ns))

    newsys.mustNowRecalculateFromScratch()
    oldsys.mustNowRecalculateFromScratch()

    t.start()
    old_total = oldsys.energy().value()
    old_ns = t.nsecsElapsed()

    t.start()
    new_total = newsys.energy().value()
    new_ns = t.nsecsElapsed()

    old_cnrg = oldsys.energy( old_clusterff.components().coulomb() ).value() + \
               oldsys.energy( old_fixedff.components().coulomb() ).value()
    old_ljnrg = oldsys.energy( old_clusterff.components().lj() ).value() + \
                oldsys.energy( old_fixedff.components().lj() ).value()

    new_cnrg = newsys.energy(new_clusterff.components().coulomb()).value()
    new_ljnrg = newsys.energy(new_clusterff.components().lj()).value()

    if verbose:
        print("\nRecalculate energy")
        print("OLD SYS:  %s  %s  %s  %s  : %s ms" %
              (old_total, old_cnrg + old_ljnrg, old_cnrg, old_ljnrg,
               0.000001 * old_ns))
        print("NEW SYS:  %s  %s  %s  %s  : %s ms" %
              (new_total, new_cnrg + new_ljnrg, new_cnrg, new_ljnrg,
               0.000001 * new_ns))
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 #31
0
protoms = ProtoMS("%s/protoms2" % protoms_dir)

protoms.addParameterFile("%s/parameter/amber99.ff" % protoms_dir)
protoms.addParameterFile("%s/parameter/gaff.ff" % protoms_dir)
protoms.addParameterFile("test/ff/sb2.ff")

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

qmff = QMFF("MopacFF")
mopac = Mopac()
qmff.setQuantumProgram(mopac)

qmff.add(sb2)

system = System()

system.add(qmff)

zmat_move = ZMatMove(qmff[MGIdx(0)])

moves = SameMoves(zmat_move)

import Sire.Stream

Sire.Stream.save((system, moves), "test/Squire/mopacsim.s3")

print("Energy before == %f kcal mol-1" % system.energy().to(kcal_per_mol))
system = moves.move(system)
print("Energy after == %f kcal mol-1" % system.energy().to(kcal_per_mol))
Exemple #32
0
rb_moves.setMaximumTranslation(max_translate)
rb_moves.setTemperature(temperature)

# create volume moves to change the box size
vol_moves = VolumeMove(mols)
vol_moves.setMaximumVolumeChange( mols.nMolecules() * 0.1 * angstrom3 )
vol_moves.setTemperature(temperature)
vol_moves.setPressure(pressure)

# group these two moves together
moves = WeightedMoves()
moves.add( rb_moves, mols.nMolecules() )
moves.add( vol_moves, 1 )

# print the initial energy and coordinates
print("0:   %s" % system.energy())
PDB().write(system.molecules(), "output000000.pdb") 

# now run the simulation in blocks of 1000 moves
nmoves = 0
while nmoves < num_moves:
    system = moves.move(system, 1000, False)
    nmoves += 1000

    # print out the energy and coordinates every 1000 moves
    print("%s  %s" % (nmoves, system.energy()))
    print(moves)

    PDB().write(system.molecules(), "output%000006d.pdb" % nmoves)

print("Complete!")
Exemple #33
0
                                              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 ") 
print("""
# NSTEP =        0   TIME(PS) =       0.000  TEMP(K) =     0.00  PRESS =     0.0
# Etot   =    -47010.2216  EKtot   =         0.0000  EPtot      =    -47010.2216
# BOND   =       898.1982  ANGLE   =      5310.2620  DIHED      =      2922.5644
# 1-4 NB =       790.8755  1-4 EEL =      7702.0145  VDWAALS    =      7345.0484
# EELEC  =    -71979.1846  EHBOND  =         0.0000  RESTRAINT  =         0.0000
Exemple #34
0
print(intraff.energy() + intraclj.energy())

print(qmff.energy())

solute = MoleculeGroup("solute")
solute.add(mol)

system = System()

system.add(qmff)
system.add(intraff)
system.add(intraclj)

system.add(solute)

print(system.energy())

chg_constraint = QMChargeConstraint(solute)
chg_constraint.setChargeCalculator( AM1BCC() )

system.add(chg_constraint)

print(system.constraintsSatisfied())

print(system.energy())

print(system.constraintsSatisfied())

mol = system[ MGIdx(0) ][ mol.number() ].molecule()

print(mol.property("charge").array())
Exemple #35
0
                    .setProperty("LJ", ljs) \
             .commit()

    solvent.add(mol)

    cljff.add(mol)

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

system = System()
system.add(solvent)
system.add(cljff)

t.start()
print("Initial energy = %s" % system.energy())
print("(took %d ms)" % t.elapsed())
print(system.property("space"))
print(system.property("switchingFunction"))

print(system.groupNumbers())
print(system.groupNames())
print(system.energies())

mc = RigidBodyMC(solvent)

moves = SameMoves(mc)

moves.setGenerator( RanGenerator(42) )

print("Running 10000 moves without saving the trajectory...")
Exemple #36
0
    mol = mol.edit().rename("T4P") \
                    .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)

t.start()
nrg = system.energy()
ms = t.elapsed()

print("Energy = %f kcal mol-1 - took %d ms" % (nrg.to(kcal_per_mol), ms))

closemols1 = CloseMols( Vector(0,0,0), cljff[MGIdx(0)], 10 )
closemols2 = CloseMols( Vector(0,0,0), cljff[MGIdx(0)], 20 )
closemols3 = CloseMols( Vector(0,0,0), cljff[MGIdx(0)], 1 )

closemols1.update(system)
closemols2.update(system)
closemols3.update(system)

mols1 = list(closemols1.closeMolecules().keys())
mols1.sort()
Exemple #37
0
print(intraff.energy() + intraclj.energy())

print(qmff.energy())

solute = MoleculeGroup("solute")
solute.add(mol)

system = System()

system.add(qmff)
system.add(intraff)
system.add(intraclj)

system.add(solute)

print(system.energy())

chg_constraint = QMChargeConstraint(solute)
chg_constraint.setChargeCalculator(AM1BCC())

system.add(chg_constraint)

print(system.constraintsSatisfied())

print(system.energy())

print(system.constraintsSatisfied())

mol = system[MGIdx(0)][mol.number()].molecule()

print(mol.property("charge").array())
Exemple #38
0
system = System()

for forcefield in forcefields:
    forcefield.add(waters)
    system.add(forcefield)

def printEnergies(nrgs):
    keys = list(nrgs.keys())
    keys.sort()

    for key in keys:
        print("%25s : %12.8f" % (key, nrgs[key]))

system.setProperty("space", space)
system.setProperty("switchingFunction", switchfunc)

printEnergies(system.energies())
 
print("\nEnergy with respect to cutoff length\n")
print("  Distance   Group    Shifted    ReactionField   Atomistic")

for i in range(10,200,5):
    x = i*0.1

    switchfunc = HarmonicSwitchingFunction(x*angstrom, (x-0.5)*angstrom)
    system.setProperty("switchingFunction", switchfunc)

    print("%12.8f  %12.8f  %12.8f  %12.8f  %12.8f" % (x, system.energy(group_coul).value(),
              system.energy(shift_coul).value(), system.energy(field_coul).value(),
              system.energy(atom_coul).value()))
Exemple #39
0
solvent_move = RigidBodyMC( PrefSampler(solute.moleculeAt(0), solvent, 200*angstrom2) )
solvent_move.setMaximumTranslation( 0.2 * angstrom )
solvent_move.setMaximumRotation( 5 * degrees )

solute_move = RigidBodyMC( solute )
solute_move.setMaximumTranslation( 0.2 * angstrom )
solute_move.setMaximumRotation( 5 * degrees )

moves = WeightedMoves()
moves.add( solvent_move, 100 )
moves.add( solute_move, 1 )

for i in range(1,11):
    system = moves.move(system, 5000, False )
    #system = moves.move(system, 50, False)
    print("Step %d of 10: Energy = %s" % (i, system.energy()))

    PDB().write(system.molecules(), "test_equil_%0004d.pdb" % i)

print("Equilibration complete")

print("Adding energy monitors...")

identity_points = []

for atom in identity_atoms:
    identity_points.append( AtomPoint( solute.moleculeAt(0).atom(AtomName(atom)) ) )

idassigner = IDAssigner(identity_points, solvent)

nrgmon0 = EnergyMonitor(solute, solvent)
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 #41
0
    c2 = Sire.Stream.load(data)

    ms = t.elapsed()

    print(("Reading the data took %d ms" % ms))
    print(c)
    print(c2)


testStream(system)

data = Sire.Stream.save(system)

print("Probing the system...")
print((system.energy()))
print((system.energies()))

system = Sire.Stream.load(data)

print((system.energy()))
print((system.energies()))

print("\nGetting data info...")

t.start()
Sire.Stream.save(system, "test/SireStream/tmp_testdata.sire")
ms = t.elapsed()

print(("Saving a system to a file took %d ms" % ms))
Exemple #42
0
system = System()

# Add the CLJ forcefield to the system
system.add(cljff)

# Add the molecule group containing the waters to the system - we will give
# this molecule group the name 'waters' so that we can extract it from
# the system at a later point in the script
waters.setName("waters")
system.add(waters)

# Add a constraint that waters are mapped back into the periodic box
system.add( SpaceWrapper(Vector(0,0,0), waters) )

print "Calculating the starting energy... (should be -16364.5 kcal mol-1)"
print "...Initial energy = %s" % system.energy()

# Now create the rigid body move (RigidBodyMC, from Sire.Move) that act on the waters
rbmc = RigidBodyMC(waters)

# Set the maximum amount by which to translate and rotate the water molecules
# to 0.25 A and 15 degrees (angstrom and degrees are from Sire.Units)
rbmc.setMaximumTranslation( 0.25*angstrom )
rbmc.setMaximumRotation( 15*degrees )

# Set the temperature of the moves to 25 Celsius (Celsius is from Sire.Units)
rbmc.setTemperature( 25*celsius )

# Now create the volume move (VolumeMove, from Sire.Move) that maintains a constant pressure
volmc = VolumeMove(waters)
Exemple #43
0
for i in range(1,7):
    mol = mols.moleculeAt(i).molecule()

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

    solvent.add(mol)
    cljff.add(mol)

system = System()
system.add(solvent)
system.add(cljff)

print(system.energy())

rbmove = MolecularDynamics( solvent, DLMRigidBody(), 1*femtosecond )

#rbmove.setEnergyComponent( cljff.components().coulomb() )

PDB().write(system.molecules(), "test0000.pdb")

for i in range(1,1000):
    rbmove.move(system, 10)
    print(i, system.energy())
    print(rbmove.kineticEnergy(), (system.energy() + rbmove.kineticEnergy()))

    PDB().write(system.molecules(), "test%0004d.pdb" % i)

Exemple #44
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 #45
0
cljff = InterCLJFF("salt-salt")
cljff.add(salt)
internalff.add(salt)

system = System()
system.add(salt)
system.add(cljff)
system.add(internalff)

system.setProperty("space", PeriodicBox( Vector(20,20,20) ) )

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

t.start()                                       
print("Initial energy = %s" % system.energy())
print("(took %d ms)" % t.elapsed())

mdmove = MolecularDynamics( salt, VelocityVerlet(), 
                            {"velocity generator":MaxwellBoltzmann(25*celsius)} )

mdmove = MolecularDynamics(salt, DLMRigidBody() )

mdmove.setTimeStep(1*femtosecond)
do_mc = False

intra_mcmove = InternalMove(salt)
inter_mcmove = RigidBodyMC(salt)

mcmove = WeightedMoves()
mcmove.add(intra_mcmove)
Exemple #46
0
    cljff.add(mol)

    if i > 3:
        free_mols.add(mol)
    else:
        sync_mols.add(mol)

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

system = System()

system.add(cljff)

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

mc = RigidBodyMC(free_mols)
sync_mc = RigidBodyMC(sync_mols)
sync_mc.setSynchronisedTranslation(True)
sync_mc.setSynchronisedRotation(True)

nodes = Cluster.getNode()
this_thread = nodes.borrowThisThread()

moves = WeightedMoves()
moves.add(mc, 2)
moves.add(sync_mc, 1)

for i in range(0,10):
    print(i+1)
Exemple #47
0
    mol = mol.edit().rename("T4P") \
                    .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)

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

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

moves = SameMoves(mc)

print("Running 1000 moves directly...")
t.start()
system = moves.move(system, 1000, True)
ms = t.elapsed()
print("Direct moves took %d ms" % ms)

print("Running 1000 simulation moves...")

t.start()
sim = Simulation.run(system, moves, 1000)
Exemple #48
0
for i in range(0,len(lambda_values)):
    replicas.setLambdaValue(i, lambda_values[i])

zmatmove = ZMatMove( internalff.groups()[0] )
zmatmove.setTemperature( 298 * kelvin )

nsubmoves = 1000

replicas.setSubMoves( SameMoves(zmatmove) )
replicas.setNSubMoves(nsubmoves)

# Average energy should be 1/2 kT
theo_nrg = 0.5 * gasr * 298

print("Running a simulation - initial energy = %f kcal mol-1" % system.energy().to(kcal_per_mol))

repexmove = RepExMove()

lambda_trajectory = []

i = -1

def printInfo(replicas):

    lamtraj = replicas.lambdaTrajectory()
    lambda_trajectory.append(lamtraj)

    ids = replicas.replicaIDs()

    for j in range(0,replicas.count()):
Exemple #49
0
            else:
                na = na.edit().renumber() \
                       .setProperty("coordinates", AtomCoords([coords]) ) \
                       .commit()

                salt.add(na)
                add_cl = True

cljff = InterCLJFF("salt-salt")
cljff.add(salt)

system = System()
system.add(salt)
system.add(cljff)

t.start()
print("Initial energy = %s" % system.energy())
print("(took %d ms)" % t.elapsed())

hmcmove = HybridMC(salt, 100)

print(system.property("space"))

for i in range(0, 250):
    print("\nmove %d" % (i + 1))
    hmcmove.move(system, 1)

    print(system.energy())

    PDB().write(system.molecules(), "test%0004d.pdb" % i)
def test_system(verbose=False):

    cljff = InterCLJFF()

    mincoords = Vector(-18.3854, -18.66855, -18.4445)
    maxcoords = Vector( 18.3854,  18.66855,  18.4445)

    vol = PeriodicBox(mincoords, maxcoords)

    cljff.setSpace(vol)

    mols = PDB().read("../io/water.pdb")
                                                
    if verbose:
        print("Read in %d molecules!" % mols.nMolecules())

    i = 0

    mol = mols.moleculeAt(0).molecule()

    mol = mol.edit().atom( AtomName("O00") ) \
                        .setProperty("LJ", LJParameter(3.15363*angstrom,  \
                                                   0.1550*kcal_per_mol)).molecule() \
                    .atom( AtomName("H01") ) \
                        .setProperty("charge", 0.520 * mod_electron).molecule() \
                    .atom( AtomName("H02") ) \
                        .setProperty("charge", 0.520 * mod_electron).molecule() \
                    .atom( AtomName("M03") ) \
                        .setProperty("charge", -1.04 * mod_electron).molecule() \
             .commit()

    charges = mol.property("charge")
    ljs = mol.property("LJ")

    cljff.add(mol)

    for i in range(1, mols.nMolecules()):
        mol = mols.moleculeAt(i).molecule()

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

        cljff.add(mol)

    system = System()

    system.add(cljff)

    nrg = system.energy()

    if verbose:
        print("System energy = %s" % (nrg))

    copy_system = System(system)

    nrg2 = copy_system.energy()

    if verbose:
        print("Copy energy: %s (should be %s)" % (nrg2,nrg))

    assert_almost_equal(nrg.value(), nrg2.value(), 5)

    copy_system.mustNowRecalculateFromScratch()
    nrg3 = copy_system.energy()

    if verbose:
        print("Copy energy: %s (should be %s)" % (nrg2,nrg))

    assert_almost_equal(nrg.value(), nrg3.value(), 5)
Exemple #51
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