Search in sources :

Example 1 with MultiDoubleArray

use of ffx.numerics.MultiDoubleArray in project ffx by mjschnie.

the class VanDerWaals method initAtomArrays.

/**
 * Allocate coordinate arrays and set up reduction indices and values.
 */
private void initAtomArrays() {
    if (esvTerm) {
        atoms = esvSystem.getExtendedAtoms();
        nAtoms = atoms.length;
    }
    if (atomClass == null || nAtoms > atomClass.length || lambdaTerm || esvTerm) {
        atomClass = new int[nAtoms];
        coordinates = new double[nAtoms * 3];
        reduced = new double[nSymm][nAtoms * 3];
        reducedXYZ = reduced[0];
        reductionIndex = new int[nAtoms];
        reductionValue = new double[nAtoms];
        bondMask = new int[nAtoms][];
        angleMask = new int[nAtoms][];
        if (vdwForm.vdwType == VanDerWaalsForm.VDW_TYPE.LENNARD_JONES) {
            torsionMask = new int[nAtoms][];
        } else {
            torsionMask = null;
        }
        use = new boolean[nAtoms];
        isSoft = new boolean[nAtoms];
        softCore = new boolean[2][nAtoms];
        lambdaGradX = null;
        lambdaGradY = null;
        lambdaGradZ = null;
        switch(atomicDoubleArrayImpl) {
            case MULTI:
                gradX = new MultiDoubleArray(threadCount, nAtoms);
                gradY = new MultiDoubleArray(threadCount, nAtoms);
                gradZ = new MultiDoubleArray(threadCount, nAtoms);
                if (lambdaTerm) {
                    lambdaGradX = new MultiDoubleArray(threadCount, nAtoms);
                    lambdaGradY = new MultiDoubleArray(threadCount, nAtoms);
                    lambdaGradZ = new MultiDoubleArray(threadCount, nAtoms);
                }
                break;
            case PJ:
                gradX = new PJDoubleArray(threadCount, nAtoms);
                gradY = new PJDoubleArray(threadCount, nAtoms);
                gradZ = new PJDoubleArray(threadCount, nAtoms);
                if (lambdaTerm) {
                    lambdaGradX = new PJDoubleArray(threadCount, nAtoms);
                    lambdaGradY = new PJDoubleArray(threadCount, nAtoms);
                    lambdaGradZ = new PJDoubleArray(threadCount, nAtoms);
                }
                break;
            case ADDER:
            default:
                gradX = new AdderDoubleArray(threadCount, nAtoms);
                gradY = new AdderDoubleArray(threadCount, nAtoms);
                gradZ = new AdderDoubleArray(threadCount, nAtoms);
                if (lambdaTerm) {
                    lambdaGradX = new AdderDoubleArray(threadCount, nAtoms);
                    lambdaGradY = new AdderDoubleArray(threadCount, nAtoms);
                    lambdaGradZ = new AdderDoubleArray(threadCount, nAtoms);
                }
                break;
        }
    }
    /**
     * Initialize all atoms to be used in the energy.
     */
    fill(use, true);
    fill(isSoft, false);
    fill(softCore[HARD], false);
    fill(softCore[SOFT], false);
    softCoreInit = false;
    // Needs initialized regardless of esvTerm.
    esvAtoms = new boolean[nAtoms];
    esvLambda = new double[nAtoms];
    atomEsvID = new int[nAtoms];
    fill(esvAtoms, false);
    fill(esvLambda, 1.0);
    fill(atomEsvID, -1);
    if (esvTerm) {
        updateEsvLambda();
    }
    lambdaFactors = new LambdaFactors[threadCount];
    for (int i = 0; i < threadCount; i++) {
        if (esvTerm) {
            lambdaFactors[i] = new LambdaFactorsESV();
        } else if (lambdaTerm) {
            lambdaFactors[i] = new LambdaFactorsOSRW();
        } else {
            lambdaFactors[i] = new LambdaFactors();
        }
    }
    for (int i = 0; i < nAtoms; i++) {
        Atom ai = atoms[i];
        assert (i == ai.getXyzIndex() - 1);
        double[] xyz = ai.getXYZ(null);
        int i3 = i * 3;
        coordinates[i3 + XX] = xyz[XX];
        coordinates[i3 + YY] = xyz[YY];
        coordinates[i3 + ZZ] = xyz[ZZ];
        AtomType atomType = ai.getAtomType();
        if (atomType == null) {
            logger.severe(ai.toString());
            // Severe no longer guarantees program crash.
            continue;
        }
        String vdwIndex = forceField.getString(ForceField.ForceFieldString.VDWINDEX, "Class");
        if (vdwIndex.equalsIgnoreCase("Type")) {
            atomClass[i] = atomType.type;
        } else {
            atomClass[i] = atomType.atomClass;
        }
        VDWType type = forceField.getVDWType(Integer.toString(atomClass[i]));
        if (type == null) {
            logger.info(" No VdW type for atom class " + atomClass[i]);
            logger.severe(" No VdW type for atom " + ai.toString());
            return;
        }
        ai.setVDWType(type);
        ArrayList<Bond> bonds = ai.getBonds();
        int numBonds = bonds.size();
        if (type.reductionFactor > 0.0 && numBonds == 1) {
            Bond bond = bonds.get(0);
            Atom heavyAtom = bond.get1_2(ai);
            // Atom indexes start at 1
            reductionIndex[i] = heavyAtom.getIndex() - 1;
            reductionValue[i] = type.reductionFactor;
        } else {
            reductionIndex[i] = i;
            reductionValue[i] = 0.0;
        }
        bondMask[i] = new int[numBonds];
        for (int j = 0; j < numBonds; j++) {
            Bond bond = bonds.get(j);
            bondMask[i][j] = bond.get1_2(ai).getIndex() - 1;
        }
        ArrayList<Angle> angles = ai.getAngles();
        int numAngles = 0;
        for (Angle angle : angles) {
            Atom ak = angle.get1_3(ai);
            if (ak != null) {
                numAngles++;
            }
        }
        angleMask[i] = new int[numAngles];
        int j = 0;
        for (Angle angle : angles) {
            Atom ak = angle.get1_3(ai);
            if (ak != null) {
                angleMask[i][j++] = ak.getIndex() - 1;
            }
        }
        if (vdwForm.scale14 != 1.0) {
            ArrayList<Torsion> torsions = ai.getTorsions();
            int numTorsions = 0;
            for (Torsion torsion : torsions) {
                Atom ak = torsion.get1_4(ai);
                if (ak != null) {
                    numTorsions++;
                }
            }
            torsionMask[i] = new int[numTorsions];
            j = 0;
            for (Torsion torsion : torsions) {
                Atom ak = torsion.get1_4(ai);
                if (ak != null) {
                    torsionMask[i][j++] = ak.getIndex() - 1;
                }
            }
        }
    }
}
Also used : MultiDoubleArray(ffx.numerics.MultiDoubleArray) Atom(ffx.potential.bonded.Atom) PJDoubleArray(ffx.numerics.PJDoubleArray) VDWType(ffx.potential.parameters.VDWType) Angle(ffx.potential.bonded.Angle) AtomType(ffx.potential.parameters.AtomType) Bond(ffx.potential.bonded.Bond) Torsion(ffx.potential.bonded.Torsion) AdderDoubleArray(ffx.numerics.AdderDoubleArray)

Aggregations

AdderDoubleArray (ffx.numerics.AdderDoubleArray)1 MultiDoubleArray (ffx.numerics.MultiDoubleArray)1 PJDoubleArray (ffx.numerics.PJDoubleArray)1 Angle (ffx.potential.bonded.Angle)1 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 Torsion (ffx.potential.bonded.Torsion)1 AtomType (ffx.potential.parameters.AtomType)1 VDWType (ffx.potential.parameters.VDWType)1