Search in sources :

Example 1 with Atom

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

the class XRayEnergy method getMass.

/**
 * {@inheritDoc}
 */
@Override
public double[] getMass() {
    double[] mass = new double[nXYZ + nB + nOCC];
    int i = 0;
    if (refineXYZ) {
        for (Atom a : activeAtomArray) {
            double m = a.getMass();
            mass[i++] = m;
            mass[i++] = m;
            mass[i++] = m;
        }
    }
    if (refineB) {
        for (int j = i; j < nXYZ + nB; i++, j++) {
            mass[j] = bMass;
        }
    }
    if (refineOCC) {
        for (int j = i; j < nXYZ + nB + nOCC; i++, j++) {
            mass[j] = occMass;
        }
    }
    return mass;
}
Also used : Atom(ffx.potential.bonded.Atom)

Example 2 with Atom

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

the class XRayEnergy method energyAndGradient.

/**
 * {@inheritDoc}
 */
@Override
public double energyAndGradient(double[] x, double[] g) {
    double e = 0.0;
    /**
     * Unscale the coordinates.
     */
    if (optimizationScaling != null) {
        int len = x.length;
        for (int i = 0; i < len; i++) {
            x[i] /= optimizationScaling[i];
        }
    }
    if (refineXYZ) {
        for (Atom a : activeAtomArray) {
            a.setXYZGradient(0.0, 0.0, 0.0);
            a.setLambdaXYZGradient(0.0, 0.0, 0.0);
        }
        // update coordinates
        diffractionData.setFFTCoordinates(x);
    }
    if (refineB) {
        for (Atom a : activeAtomArray) {
            a.setTempFactorGradient(0.0);
            if (a.getAnisou(null) != null) {
                if (a.getAnisouGradient(null) == null) {
                    double[] ganisou = new double[6];
                    a.setAnisouGradient(ganisou);
                } else {
                    double[] ganisou = a.getAnisouGradient(null);
                    ganisou[0] = ganisou[1] = ganisou[2] = 0.0;
                    ganisou[3] = ganisou[4] = ganisou[5] = 0.0;
                    a.setAnisouGradient(ganisou);
                }
            }
        }
        // update B factors
        setBFactors(x);
    }
    if (refineOCC) {
        for (Atom a : activeAtomArray) {
            a.setOccupancyGradient(0.0);
        }
        // update occupancies
        setOccupancies(x);
    }
    if (xrayTerms) {
        if (lambdaTerm) {
            diffractionData.setLambdaTerm(false);
        }
        // compute new structure factors
        diffractionData.computeAtomicDensity();
        // compute crystal likelihood
        e = diffractionData.computeLikelihood();
        // compute the crystal gradients
        diffractionData.computeAtomicGradients(refinementMode);
        if (refineXYZ) {
            // pack gradients into gradient array
            getXYZGradients(g);
        }
        if (lambdaTerm) {
            int n = dUdXdL.length;
            System.arraycopy(g, 0, dUdXdL, 0, n);
            for (Atom a : activeAtomArray) {
                a.setXYZGradient(0.0, 0.0, 0.0);
                a.setLambdaXYZGradient(0.0, 0.0, 0.0);
            }
            // Turn off all atoms scaled by lambda.
            diffractionData.setLambdaTerm(true);
            // Compute new structure factors.
            diffractionData.computeAtomicDensity();
            // Compute crystal likelihood.
            double e2 = diffractionData.computeLikelihood();
            // compute the crystal gradients
            diffractionData.computeAtomicGradients(refinementMode);
            dEdL = e - e2;
            e = lambda * e + (1.0 - lambda) * e2;
            getXYZGradients(g2);
            for (int i = 0; i < g.length; i++) {
                dUdXdL[i] -= g2[i];
                g[i] = lambda * g[i] + (1.0 - lambda) * g2[i];
            }
            diffractionData.setLambdaTerm(false);
        }
    }
    if (restraintTerms) {
        if (refineB) {
            // add B restraints
            e += getBFactorRestraints();
            // pack gradients into gradient array
            getBFactorGradients(g);
        }
        if (refineOCC) {
            // pack gradients into gradient array
            getOccupancyGradients(g);
        }
    }
    /**
     * Scale the coordinates and gradients.
     */
    if (optimizationScaling != null) {
        int len = x.length;
        for (int i = 0; i < len; i++) {
            x[i] *= optimizationScaling[i];
            g[i] /= optimizationScaling[i];
        }
    }
    totalEnergy = e;
    return e;
}
Also used : Atom(ffx.potential.bonded.Atom)

Example 3 with Atom

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

the class XRayEnergy method getCoordinates.

/**
 * {@inheritDoc}
 */
@Override
public double[] getCoordinates(double[] x) {
    assert (x != null);
    double[] xyz = new double[3];
    int index = 0;
    fill(x, 0.0);
    if (refineXYZ) {
        for (Atom a : activeAtomArray) {
            a.getXYZ(xyz);
            x[index++] = xyz[0];
            x[index++] = xyz[1];
            x[index++] = xyz[2];
        }
    }
    if (refineB) {
        double[] anisou = null;
        int resnum = -1;
        int nat = 0;
        int nres = diffractionData.getnResidueBFactor() + 1;
        for (Atom a : activeAtomArray) {
            // ignore hydrogens!!!
            if (a.getAtomicNumber() == 1) {
                continue;
            }
            if (a.getAnisou(null) != null) {
                anisou = a.getAnisou(anisou);
                x[index++] = anisou[0];
                x[index++] = anisou[1];
                x[index++] = anisou[2];
                x[index++] = anisou[3];
                x[index++] = anisou[4];
                x[index++] = anisou[5];
            } else if (diffractionData.isResidueBFactor()) {
                if (resnum != a.getResidueNumber()) {
                    if (nres >= diffractionData.getnResidueBFactor()) {
                        if (resnum > -1 && index < nXYZ + nB - 1) {
                            x[index] /= nat;
                            index++;
                        }
                        nat = 1;
                        nres = 1;
                    } else {
                        nres++;
                        nat++;
                    }
                    x[index] += a.getTempFactor();
                    resnum = a.getResidueNumber();
                } else {
                    x[index] += a.getTempFactor();
                    nat++;
                }
            } else {
                x[index++] = a.getTempFactor();
            }
        }
        if (diffractionData.isResidueBFactor()) {
            if (nat > 1) {
                x[index] /= nat;
            }
        }
    }
    if (refineOCC) {
        for (ArrayList<Residue> list : refinementModel.getAltResidues()) {
            for (Residue r : list) {
                for (Atom a : r.getAtomList()) {
                    if (a.getOccupancy() < 1.0) {
                        x[index++] = a.getOccupancy();
                        break;
                    }
                }
            }
        }
        for (ArrayList<Molecule> list : refinementModel.getAltMolecules()) {
            for (Molecule m : list) {
                for (Atom a : m.getAtomList()) {
                    if (a.getOccupancy() < 1.0) {
                        x[index++] = a.getOccupancy();
                        break;
                    }
                }
            }
        }
    }
    return x;
}
Also used : Molecule(ffx.potential.bonded.Molecule) Residue(ffx.potential.bonded.Residue) Atom(ffx.potential.bonded.Atom)

Example 4 with Atom

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

the class XRayEnergy method getOccupancyGradients.

/**
 * Fill gradient array with occupancy gradients.
 * Note: this also acts to constrain the occupancies
 * by moving the gradient vector COM to zero
 *
 * @param g array to add gradients to
 */
public void getOccupancyGradients(double[] g) {
    double ave;
    int index = nXYZ + nB;
    // First: Alternate Residues
    for (ArrayList<Residue> list : refinementModel.getAltResidues()) {
        ave = 0.0;
        for (Residue r : list) {
            for (Atom a : r.getAtomList()) {
                if (a.getOccupancy() < 1.0) {
                    ave += a.getOccupancyGradient();
                }
            }
        }
        /*
             * should this be normalized with respect
             * to number of atoms in residue in addition
             * to the number of conformers?
             */
        ave /= list.size();
        for (Residue r : list) {
            for (Atom a : r.getAtomList()) {
                if (a.getOccupancy() < 1.0) {
                    g[index] += a.getOccupancyGradient();
                }
            }
            if (list.size() > 1) {
                // subtract average to move COM to zero
                g[index] -= ave;
            }
            index++;
        }
    }
    // Now the molecules (HETATMs).
    for (ArrayList<Molecule> list : refinementModel.getAltMolecules()) {
        ave = 0.0;
        for (Molecule m : list) {
            for (Atom a : m.getAtomList()) {
                if (a.getOccupancy() < 1.0) {
                    ave += a.getOccupancyGradient();
                }
            }
        }
        ave /= list.size();
        for (Molecule m : list) {
            for (Atom a : m.getAtomList()) {
                if (a.getOccupancy() < 1.0) {
                    g[index] += a.getOccupancyGradient();
                }
            }
            if (list.size() > 1) {
                g[index] -= ave;
            }
            index++;
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) Residue(ffx.potential.bonded.Residue) Atom(ffx.potential.bonded.Atom)

Example 5 with Atom

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

the class GraphicsPicking method measure.

/**
 * @param measureLevel
 * @param atoms
 */
private void measure() {
    String measurement = null;
    double value = 0.0;
    Atom a1, a2, a3, a4;
    switch(pickLevel) {
        case MEASUREDISTANCE:
            if (atomCache.size() < 2) {
                return;
            }
            a1 = atomCache.get(0);
            a2 = atomCache.get(1);
            distance(a1, a);
            distance(a2, b);
            value = ffx.numerics.VectorMath.dist(a, b);
            measurement = "\nDistance\t" + a1.getIndex() + ", " + a2.getIndex() + ":   \t" + String.format("%10.5f", value);
            break;
        case MEASUREANGLE:
            if (atomCache.size() < 3) {
                return;
            }
            a1 = atomCache.get(0);
            a2 = atomCache.get(1);
            a3 = atomCache.get(2);
            distance(a1, a);
            distance(a2, b);
            distance(a3, c);
            value = ffx.numerics.VectorMath.bondAngle(a, b, c);
            value = Math.toDegrees(value);
            measurement = "\nAngle\t" + a1.getIndex() + ", " + a2.getIndex() + ", " + a3.getIndex() + ":   \t" + String.format("%10.5f", value);
            break;
        case MEASUREDIHEDRAL:
            if (atomCache.size() < 4) {
                return;
            }
            a1 = atomCache.get(0);
            a2 = atomCache.get(1);
            a3 = atomCache.get(2);
            a4 = atomCache.get(3);
            distance(a1, a);
            distance(a2, b);
            distance(a3, c);
            distance(a4, d);
            value = ffx.numerics.VectorMath.dihedralAngle(a, b, c, d);
            value = Math.toDegrees(value);
            measurement = "\nDihedral\t" + a1.getIndex() + ", " + a2.getIndex() + ", " + a3.getIndex() + ", " + a4.getIndex() + ":\t" + String.format("%10.5f", value);
            break;
        default:
            return;
    }
    logger.info(measurement);
    ModelingShell modelingShell = mainPanel.getModelingShell();
    modelingShell.setMeasurement(measurement, value);
    count = 0;
}
Also used : Atom(ffx.potential.bonded.Atom)

Aggregations

Atom (ffx.potential.bonded.Atom)206 Residue (ffx.potential.bonded.Residue)42 Bond (ffx.potential.bonded.Bond)37 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)34 ArrayList (java.util.ArrayList)33 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)23 Polymer (ffx.potential.bonded.Polymer)22 IOException (java.io.IOException)22 MSNode (ffx.potential.bonded.MSNode)21 Crystal (ffx.crystal.Crystal)20 Molecule (ffx.potential.bonded.Molecule)19 File (java.io.File)19 MultiResidue (ffx.potential.bonded.MultiResidue)17 MultipoleType (ffx.potential.parameters.MultipoleType)13 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)12 PointerByReference (com.sun.jna.ptr.PointerByReference)11 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)11 AtomType (ffx.potential.parameters.AtomType)11 List (java.util.List)11 MolecularAssembly (ffx.potential.MolecularAssembly)10