Search in sources :

Example 1 with TorsionTorsion

use of ffx.potential.bonded.TorsionTorsion in project ffx by mjschnie.

the class ForceFieldEnergyOpenMM method addTorsionTorsionForce.

private void addTorsionTorsionForce() {
    TorsionTorsion[] torsionTorsions = super.getTorsionTorsions();
    if (torsionTorsions == null || torsionTorsions.length < 1) {
        return;
    }
    /**
     * Load the torsion-torsions.
     */
    int nTypes = 0;
    LinkedHashMap<String, TorsionTorsionType> torTorTypes = new LinkedHashMap<>();
    int nTorsionTorsions = torsionTorsions.length;
    amoebaTorsionTorsionForce = OpenMM_AmoebaTorsionTorsionForce_create();
    for (int i = 0; i < nTorsionTorsions; i++) {
        TorsionTorsion torsionTorsion = torsionTorsions[i];
        int ia = torsionTorsion.getAtom(0).getXyzIndex() - 1;
        int ib = torsionTorsion.getAtom(1).getXyzIndex() - 1;
        int ic = torsionTorsion.getAtom(2).getXyzIndex() - 1;
        int id = torsionTorsion.getAtom(3).getXyzIndex() - 1;
        int ie = torsionTorsion.getAtom(4).getXyzIndex() - 1;
        TorsionTorsionType torsionTorsionType = torsionTorsion.torsionTorsionType;
        String key = torsionTorsionType.getKey();
        /**
         * Check if the TorTor parameters have already been added to the
         * Hash.
         */
        int gridIndex = 0;
        if (torTorTypes.containsKey(key)) {
            /**
             * If the TorTor has been added, get its (ordered) index in the
             * Hash.
             */
            int index = 0;
            for (String entry : torTorTypes.keySet()) {
                if (entry.equalsIgnoreCase(key)) {
                    gridIndex = index;
                    break;
                } else {
                    index++;
                }
            }
        } else {
            /**
             * Add the new TorTor.
             */
            torTorTypes.put(key, torsionTorsionType);
            gridIndex = nTypes;
            nTypes++;
        }
        Atom atom = torsionTorsion.getChiralAtom();
        int iChiral = -1;
        if (atom != null) {
            iChiral = atom.getXyzIndex() - 1;
        }
        OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion(amoebaTorsionTorsionForce, ia, ib, ic, id, ie, iChiral, gridIndex);
    }
    /**
     * Load the Torsion-Torsion parameters.
     */
    PointerByReference values = OpenMM_DoubleArray_create(6);
    int gridIndex = 0;
    for (String key : torTorTypes.keySet()) {
        TorsionTorsionType torTorType = torTorTypes.get(key);
        int nx = torTorType.nx;
        int ny = torTorType.ny;
        double[] tx = torTorType.tx;
        double[] ty = torTorType.ty;
        double[] f = torTorType.energy;
        double[] dx = torTorType.dx;
        double[] dy = torTorType.dy;
        double[] dxy = torTorType.dxy;
        /**
         * Create the 3D grid.
         */
        PointerByReference grid3D = OpenMM_3D_DoubleArray_create(nx, ny, 6);
        int xIndex = 0;
        int yIndex = 0;
        for (int j = 0; j < nx * ny; j++) {
            int addIndex = 0;
            OpenMM_DoubleArray_set(values, addIndex++, tx[xIndex]);
            OpenMM_DoubleArray_set(values, addIndex++, ty[yIndex]);
            OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * f[j]);
            OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dx[j]);
            OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dy[j]);
            OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dxy[j]);
            OpenMM_3D_DoubleArray_set(grid3D, yIndex, xIndex, values);
            xIndex++;
            if (xIndex == nx) {
                xIndex = 0;
                yIndex++;
            }
        }
        OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionGrid(amoebaTorsionTorsionForce, gridIndex++, grid3D);
        OpenMM_3D_DoubleArray_destroy(grid3D);
    }
    OpenMM_DoubleArray_destroy(values);
    OpenMM_System_addForce(system, amoebaTorsionTorsionForce);
    logger.log(Level.INFO, " Added Torsion-Torsions ({0})", nTorsionTorsions);
}
Also used : TorsionTorsionType(ffx.potential.parameters.TorsionTorsionType) PointerByReference(com.sun.jna.ptr.PointerByReference) OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion(simtk.openmm.AmoebaOpenMMLibrary.OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion) TorsionTorsion(ffx.potential.bonded.TorsionTorsion) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint) Atom(ffx.potential.bonded.Atom) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)1 Atom (ffx.potential.bonded.Atom)1 TorsionTorsion (ffx.potential.bonded.TorsionTorsion)1 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)1 TorsionTorsionType (ffx.potential.parameters.TorsionTorsionType)1 LinkedHashMap (java.util.LinkedHashMap)1 OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion (simtk.openmm.AmoebaOpenMMLibrary.OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion)1 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)1