Search in sources :

Example 16 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class RefinementEnergy method getdEdL.

/**
 * {@inheritDoc}
 */
@Override
public double getdEdL() {
    double dEdL = 0.0;
    if (thermostat != null) {
        kTScale = Thermostat.convert / (thermostat.getTargetTemperature() * Thermostat.kB);
    }
    int assemblysize = molecularAssemblies.length;
    /**
     * Compute the chemical energy and gradient.
     */
    for (int i = 0; i < assemblysize; i++) {
        ForceFieldEnergy forceFieldEnergy = molecularAssemblies[i].getPotentialEnergy();
        double curdEdL = forceFieldEnergy.getdEdL();
        dEdL += (curdEdL - dEdL) / (i + 1);
    }
    dEdL *= kTScale;
    double weight = data.getWeight();
    if (data instanceof DiffractionData) {
        XRayEnergy xRayEnergy = (XRayEnergy) dataEnergy;
        dEdL += weight * xRayEnergy.getdEdL();
    } else if (data instanceof RealSpaceData) {
        RealSpaceEnergy realSpaceEnergy = (RealSpaceEnergy) dataEnergy;
        dEdL += weight * realSpaceEnergy.getdEdL();
    }
    return dEdL;
}
Also used : RealSpaceData(ffx.realspace.RealSpaceData) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) RealSpaceEnergy(ffx.realspace.RealSpaceEnergy)

Example 17 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class PotentialsDataConverter method run.

/**
 * Converts the data structure to MolecularAssembly(s).
 */
@Override
public void run() {
    if (dataStructure == null || dataType.equals(Utilities.DataType.UNK)) {
        throw new IllegalArgumentException("Object passed was not recognized.");
    }
    assemblies = new ArrayList<>();
    propertyList = new ArrayList<>();
    switch(dataType) {
        case BIOJAVA:
            Structure struct = (Structure) dataStructure;
            String name = struct.getPDBCode();
            CompositeConfiguration properties = Keyword.loadProperties(file);
            MolecularAssembly assembly = new MolecularAssembly(name);
            assembly.setFile(file);
            ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
            ForceField forceField = forceFieldFilter.parse();
            assembly.setForceField(forceField);
            BiojavaFilter filter = new BiojavaFilter(struct, assembly, forceField, properties);
            if (filter.convert()) {
                filter.applyAtomProperties();
                assembly.finalize(true, forceField);
                ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
                assembly.setPotential(energy);
                assemblies.add(assembly);
                propertyList.add(properties);
                List<Character> altLocs = filter.getAltLocs();
                if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                    StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                    for (Character c : altLocs) {
                        // Do not report the root conformer.
                        if (c == ' ') {
                            continue;
                        }
                        altLocString.append(format("(%s) ", c));
                    }
                    altLocString.append("]\n");
                    logger.info(altLocString.toString());
                }
                /**
                 * Alternate conformers may have different chemistry, so
                 * they each need to be their own MolecularAssembly.
                 */
                for (Character c : altLocs) {
                    if (c.equals(' ') || c.equals('A')) {
                        continue;
                    }
                    MolecularAssembly newAssembly = new MolecularAssembly(name);
                    newAssembly.setForceField(assembly.getForceField());
                    filter.setAltID(newAssembly, c);
                    filter.clearSegIDs();
                    if (filter.convert()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                        properties.addConfiguration(properties);
                    }
                }
            } else {
                logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
            }
            activeAssembly = assembly;
            activeProperties = properties;
            break;
        case UNK:
        default:
            throw new IllegalArgumentException("Object passed was not recognized.");
    }
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) MolecularAssembly(ffx.potential.MolecularAssembly) ForceField(ffx.potential.parameters.ForceField) BiojavaFilter(ffx.potential.parsers.BiojavaFilter) Structure(org.biojava.bio.structure.Structure)

Example 18 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class ModelingShell method energy.

/**
 * <p>
 * energy</p>
 *
 * @return a {@link ffx.potential.ForceFieldEnergy} object.
 */
public ForceFieldEnergy energy() {
    if (interrupted) {
        logger.info(" Algorithm interrupted - skipping energy.");
        return null;
    }
    if (terminatableAlgorithm != null) {
        logger.info(" Algorithm already running - skipping energy.");
        return null;
    }
    MolecularAssembly active = mainPanel.getHierarchy().getActive();
    if (active != null) {
        ForceFieldEnergy energy = active.getPotentialEnergy();
        if (energy == null) {
            energy = ForceFieldEnergy.energyFactory(active);
            active.setPotential(energy);
        }
        energy.energy(false, true);
        return energy;
    }
    return null;
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) ForceFieldEnergy(ffx.potential.ForceFieldEnergy)

Example 19 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class UIFileOpener method open.

private void open() {
    if (timer) {
        startTimer();
    }
    FFXSystem ffxSystem = null;
    // Continue if the file was read in successfully.
    if (systemFilter.readFile()) {
        ffxSystem = (FFXSystem) systemFilter.getActiveMolecularSystem();
        if (!(systemFilter instanceof PDBFilter)) {
            Utilities.biochemistry(ffxSystem, systemFilter.getAtomList());
        }
        systemFilter.applyAtomProperties();
        // Add the system to the multiscale hierarchy.
        mainPanel.getHierarchy().addSystemNode(ffxSystem);
        ForceFieldEnergy energy;
        if (nThreads > 0) {
            energy = ForceFieldEnergy.energyFactory(ffxSystem, systemFilter.getCoordRestraints(), nThreads);
        } else {
            energy = ForceFieldEnergy.energyFactory(ffxSystem, systemFilter.getCoordRestraints());
        }
        ffxSystem.setPotential(energy);
        mainPanel.getHierarchy().setActive(ffxSystem);
        // Check if there are alternate conformers
        if (systemFilter instanceof PDBFilter) {
            PDBFilter pdbFilter = (PDBFilter) systemFilter;
            List<Character> altLocs = pdbFilter.getAltLocs();
            if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                for (Character c : altLocs) {
                    // Do not report the root conformer.
                    if (c == ' ') {
                        continue;
                    }
                    altLocString.append(format("(%s) ", c));
                }
                altLocString.append("]\n");
                logger.info(altLocString.toString());
            }
            /**
             * Alternate conformers may have different chemistry, so they
             * each need to be their own FFX system.
             */
            for (Character c : altLocs) {
                if (c.equals(' ') || c.equals('A')) {
                    continue;
                }
                FFXSystem newSystem = new FFXSystem(ffxSystem.getFile(), "Alternate Location " + c, ffxSystem.getProperties());
                newSystem.setForceField(ffxSystem.getForceField());
                pdbFilter.setAltID(newSystem, c);
                pdbFilter.clearSegIDs();
                if (pdbFilter.readFile()) {
                    pdbFilter.applyAtomProperties();
                    String fileName = ffxSystem.getFile().getAbsolutePath();
                    newSystem.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                    mainPanel.getHierarchy().addSystemNode(newSystem);
                    if (nThreads > 0) {
                        energy = ForceFieldEnergy.energyFactory(newSystem, systemFilter.getCoordRestraints(), nThreads);
                    } else {
                        energy = ForceFieldEnergy.energyFactory(newSystem, systemFilter.getCoordRestraints());
                    }
                    newSystem.setPotential(energy);
                }
            }
        }
    } else {
        logger.warning(String.format(" Failed to read file %s", systemFilter.getFile().getName()));
    }
    mainPanel.setCursor(Cursor.getDefaultCursor());
    if (timer) {
        stopTimer(ffxSystem);
    }
}
Also used : ForceFieldEnergy(ffx.potential.ForceFieldEnergy) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 20 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class CrystalReciprocalSpaceTest method test1NSFPermanent.

@Test
public void test1NSFPermanent() {
    String filename = "ffx/xray/structures/1NSF.pdb";
    int index = filename.lastIndexOf(".");
    String name = filename.substring(0, index);
    // load the structure
    ClassLoader cl = this.getClass().getClassLoader();
    File structure = new File(cl.getResource(filename).getPath());
    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(structure);
    Crystal crystal = new Crystal(115.996, 115.996, 44.13, 90.0, 90.0, 120.0, "P6");
    Resolution resolution = new Resolution(1.89631);
    ReflectionList reflectionList = new ReflectionList(crystal, resolution);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    // associate molecular assembly with the structure, set up forcefield
    MolecularAssembly molecularAssembly = new MolecularAssembly(name);
    molecularAssembly.setFile(structure);
    molecularAssembly.setForceField(forceField);
    PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
    pdbFile.readFile();
    pdbFile.applyAtomProperties();
    molecularAssembly.finalize(true, forceField);
    ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(molecularAssembly, pdbFile.getCoordRestraints());
    List<Atom> atomList = molecularAssembly.getAtomList();
    Atom[] atomArray = atomList.toArray(new Atom[atomList.size()]);
    // set up FFT and run it
    ParallelTeam parallelTeam = new ParallelTeam();
    CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
    crs.computeAtomicDensity(refinementData.fc);
    // tests
    ComplexNumber b = new ComplexNumber(-496.999, 431.817);
    HKL hkl = reflectionList.getHKL(1, 9, 4);
    ComplexNumber a = refinementData.getFc(hkl.index());
    System.out.println("1 9 4: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("1 9 4 reflection should be correct", -493.7799429881329, a.re(), 0.0001);
    assertEquals("1 9 4 reflection should be correct", 460.7022632345927, a.im(), 0.0001);
    b.re(-129.767);
    b.im(-76.9812);
    hkl = reflectionList.getHKL(5, 26, 8);
    a = refinementData.getFc(hkl.index());
    System.out.println("5 26 8: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("5 26 8 reflection should be correct", -123.05535567943377, a.re(), 0.0001);
    assertEquals("5 26 8 reflection should be correct", -74.59007322382718, a.im(), 0.0001);
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) HKL(ffx.crystal.HKL) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) ReflectionList(ffx.crystal.ReflectionList) ComplexNumber(ffx.numerics.ComplexNumber) Atom(ffx.potential.bonded.Atom) MolecularAssembly(ffx.potential.MolecularAssembly) ForceField(ffx.potential.parameters.ForceField) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution) Test(org.junit.Test)

Aggregations

ForceFieldEnergy (ffx.potential.ForceFieldEnergy)25 MolecularAssembly (ffx.potential.MolecularAssembly)11 File (java.io.File)6 ForceField (ffx.potential.parameters.ForceField)5 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)5 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)4 PDBFilter (ffx.potential.parsers.PDBFilter)4 ParallelTeam (edu.rit.pj.ParallelTeam)3 Crystal (ffx.crystal.Crystal)3 ReflectionList (ffx.crystal.ReflectionList)3 Resolution (ffx.crystal.Resolution)3 Atom (ffx.potential.bonded.Atom)3 ExtendedSystem (ffx.potential.extended.ExtendedSystem)3 PotentialsUtils (ffx.potential.utils.PotentialsUtils)3 RealSpaceData (ffx.realspace.RealSpaceData)3 RealSpaceEnergy (ffx.realspace.RealSpaceEnergy)3 Test (org.junit.Test)3 HKL (ffx.crystal.HKL)2 ComplexNumber (ffx.numerics.ComplexNumber)2 ExtendedSystemConfig (ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig)2