use of ffx.potential.bonded.Bond 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;
}
}
}
}
}
use of ffx.potential.bonded.Bond in project ffx by mjschnie.
the class PolarizeType method growGroup.
/**
* A recursive method that checks all atoms bonded to the seed atom for
* inclusion in the polarization group. The method is called on each newly
* found group member.
*
* @param polarizationGroup Atom types that should be included in the group.
* @param group XYZ indeces of current group members.
* @param seed The bonds of the seed atom are queried for inclusion in the
* group.
*/
private static void growGroup(List<Integer> polarizationGroup, List<Integer> group, Atom seed) {
List<Bond> bonds = seed.getBonds();
for (Bond bi : bonds) {
Atom aj = bi.get1_2(seed);
int tj = aj.getType();
boolean added = false;
for (int g : polarizationGroup) {
if (g == tj) {
Integer index = aj.getIndex() - 1;
if (!group.contains(index)) {
group.add(index);
added = true;
break;
}
}
}
if (added) {
PolarizeType polarizeType = aj.getPolarizeType();
for (int i : polarizeType.polarizationGroup) {
if (!polarizationGroup.contains(i)) {
polarizationGroup.add(i);
}
}
growGroup(polarizationGroup, group, aj);
}
}
}
use of ffx.potential.bonded.Bond in project ffx by mjschnie.
the class PolarizeType method assignPolarizationGroups.
public static void assignPolarizationGroups(Atom[] atoms, int[][] ip11, int[][] ip12, int[][] ip13) {
/**
* Find directly connected group members for each atom.
*/
List<Integer> group = new ArrayList<>();
List<Integer> polarizationGroup = new ArrayList<>();
// int g11 = 0;
for (Atom ai : atoms) {
group.clear();
polarizationGroup.clear();
Integer index = ai.getIndex() - 1;
group.add(index);
polarizationGroup.add(ai.getType());
PolarizeType polarizeType = ai.getPolarizeType();
if (polarizeType != null) {
if (polarizeType.polarizationGroup != null) {
for (int i : polarizeType.polarizationGroup) {
if (!polarizationGroup.contains(i)) {
polarizationGroup.add(i);
}
}
growGroup(polarizationGroup, group, ai);
Collections.sort(group);
ip11[index] = new int[group.size()];
int j = 0;
for (int k : group) {
ip11[index][j++] = k;
}
} else {
ip11[index] = new int[group.size()];
int j = 0;
for (int k : group) {
ip11[index][j++] = k;
}
}
// g11 += ip11[index].length;
// System.out.println(format("%d %d", index + 1, g11));
} else {
String message = "The polarize keyword was not found for atom " + (index + 1) + " with type " + ai.getType();
logger.severe(message);
}
}
/**
* Find 1-2 group relationships.
*/
int nAtoms = atoms.length;
int[] mask = new int[nAtoms];
List<Integer> list = new ArrayList<>();
List<Integer> keep = new ArrayList<>();
for (int i = 0; i < nAtoms; i++) {
mask[i] = -1;
}
for (int i = 0; i < nAtoms; i++) {
list.clear();
for (int j : ip11[i]) {
list.add(j);
mask[j] = i;
}
keep.clear();
for (int j : list) {
Atom aj = atoms[j];
ArrayList<Bond> bonds = aj.getBonds();
for (Bond b : bonds) {
Atom ak = b.get1_2(aj);
int k = ak.getIndex() - 1;
if (mask[k] != i) {
keep.add(k);
}
}
}
list.clear();
for (int j : keep) {
for (int k : ip11[j]) {
list.add(k);
}
}
Collections.sort(list);
ip12[i] = new int[list.size()];
int j = 0;
for (int k : list) {
ip12[i][j++] = k;
}
}
/**
* Find 1-3 group relationships.
*/
for (int i = 0; i < nAtoms; i++) {
mask[i] = -1;
}
for (int i = 0; i < nAtoms; i++) {
for (int j : ip11[i]) {
mask[j] = i;
}
for (int j : ip12[i]) {
mask[j] = i;
}
list.clear();
for (int j : ip12[i]) {
for (int k : ip12[j]) {
if (mask[k] != i) {
if (!list.contains(k)) {
list.add(k);
}
}
}
}
ip13[i] = new int[list.size()];
Collections.sort(list);
int j = 0;
for (int k : list) {
ip13[i][j++] = k;
}
}
}
Aggregations