Search in sources :

Example 6 with ReflectionList

use of ffx.crystal.ReflectionList in project ffx by mjschnie.

the class CNSFilter method getReflectionList.

/**
 * {@inheritDoc}
 */
@Override
public ReflectionList getReflectionList(File cnsFile, CompositeConfiguration properties) {
    try {
        BufferedReader br = new BufferedReader(new FileReader(cnsFile));
        String string;
        while ((string = br.readLine()) != null) {
            String[] strArray = string.split("\\s+");
            if (strArray[0].equalsIgnoreCase("{")) {
                if (strArray[1].toLowerCase().startsWith("sg=")) {
                    spaceGroupName = strArray[1].substring(3);
                    cell[0] = parseDouble(strArray[2].substring(2));
                    cell[1] = parseDouble(strArray[3].substring(2));
                    cell[2] = parseDouble(strArray[4].substring(2));
                    cell[3] = parseDouble(strArray[5].substring(6));
                    cell[4] = parseDouble(strArray[6].substring(5));
                    cell[5] = parseDouble(strArray[7].substring(6));
                }
            } else if (strArray[0].equalsIgnoreCase("CRYST1")) {
                cell[0] = parseDouble(strArray[1]);
                cell[1] = parseDouble(strArray[2]);
                cell[2] = parseDouble(strArray[3]);
                cell[3] = parseDouble(strArray[4]);
                cell[4] = parseDouble(strArray[5]);
                cell[5] = parseDouble(strArray[6]);
                spaceGroupName = SpaceGroup.pdb2ShortName(string.substring(55, 65));
            } else if (strArray[0].toLowerCase().startsWith("inde")) {
                break;
            }
        }
        br.close();
    } catch (IOException e) {
        String message = " CNS IO Exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }
    Resolution resolution = null;
    if (properties != null) {
        resolution = Resolution.checkProperties(properties);
        resHigh = resolution.resolution;
    }
    if (spaceGroupName != null) {
        spaceGroupNum = SpaceGroup.spaceGroupNumber(spaceGroupName);
    }
    if (spaceGroupNum < 0 || cell[0] < 0 || resolution == null) {
        logger.info(" The CNS file contains insufficient information to generate the reflection list.");
        return null;
    }
    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(format("\n Opening %s\n", cnsFile.getName()));
        sb.append(format(" Setting up Reflection List based on CNS:\n"));
        sb.append(format("  Spacegroup #: %d (name: %s)\n", spaceGroupNum, SpaceGroup.spaceGroupNames[spaceGroupNum - 1]));
        sb.append(format("  Resolution:   %8.3f\n", resHigh));
        sb.append(format("  Cell:         %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", cell[0], cell[1], cell[2], cell[3], cell[4], cell[5]));
        logger.info(sb.toString());
    }
    Crystal crystal = new Crystal(cell[0], cell[1], cell[2], cell[3], cell[4], cell[5], SpaceGroup.spaceGroupNames[spaceGroupNum - 1]);
    ReflectionList reflectionlist = new ReflectionList(crystal, resolution, properties);
    return reflectionlist;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) ReflectionList(ffx.crystal.ReflectionList) Resolution(ffx.crystal.Resolution) Crystal(ffx.crystal.Crystal)

Example 7 with ReflectionList

use of ffx.crystal.ReflectionList 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)

Example 8 with ReflectionList

use of ffx.crystal.ReflectionList in project ffx by mjschnie.

the class CIFFilterTest method testCIFFilter2DRM.

@Test
public void testCIFFilter2DRM() {
    String filename = "ffx/xray/structures/2DRM.cif";
    ClassLoader cl = this.getClass().getClassLoader();
    File cifFile = new File(cl.getResource(filename).getPath());
    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(cifFile);
    CIFFilter cifFilter = new CIFFilter();
    ReflectionList reflectionList = cifFilter.getReflectionList(cifFile);
    assertNull(" Reflection list should be null", reflectionList);
    Crystal crystal = new Crystal(29.969, 37.861, 44.506, 90.28, 90.11, 90.64, "P1");
    Resolution resolution = new Resolution(1.30);
    reflectionList = new ReflectionList(crystal, resolution);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    assertTrue(" CIF data not read correctly", cifFilter.readFile(cifFile, reflectionList, refinementData, properties));
    HKL hkl = reflectionList.getHKL(-21, -6, 7);
    assertEquals("-21 -6 7 F", 18.6, refinementData.getF(hkl.index()), 0.01);
    assertEquals("-21 -6 7 sigF", 3.6, refinementData.getSigF(hkl.index()), 0.01);
    assertEquals("-21 -6 7 freeR value", 0, refinementData.freer[hkl.index()]);
    hkl = reflectionList.getHKL(-21, -6, 8);
    assertEquals("-21 -6 7 F", 20.2, refinementData.getF(hkl.index()), 0.01);
    assertEquals("-21 -6 7 sigF", 5.0, refinementData.getSigF(hkl.index()), 0.01);
    assertEquals("-21 -6 7 freeR value", 1, refinementData.freer[hkl.index()]);
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) HKL(ffx.crystal.HKL) DiffractionRefinementData(ffx.xray.DiffractionRefinementData) ReflectionList(ffx.crystal.ReflectionList) File(java.io.File) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution) Test(org.junit.Test)

Example 9 with ReflectionList

use of ffx.crystal.ReflectionList in project ffx by mjschnie.

the class TimerTest method main.

public static void main(String[] args) {
    // Parameters collection from original Timer script
    String pdbname = System.getProperty("pdbFile", "1N7S.pdb");
    String mtzname = System.getProperty("mtzFile", null);
    String cifname = System.getProperty("cifFile", null);
    final boolean ciOnly = false;
    final String info = "SNARE complex";
    final double r = 19.412671496011;
    final double rfree = 21.555930987573;
    final double sigmaA = 0.9336853524690557;
    final double sigmaW = 0.13192537249786418;
    boolean ci = System.getProperty("ffx.ci", "false").equalsIgnoreCase("true");
    if (!ci && ciOnly) {
        crystalStats = null;
        return;
    }
    int index = pdbname.lastIndexOf(".");
    String name = pdbname.substring(0, index);
    // load the structure
    MolecularAssembly molecularAssembly;
    File structure, mtzFile, cifFile;
    structure = new File(pdbname);
    PotentialsFileOpener opener = new PotentialsFileOpener(structure);
    opener.run();
    molecularAssembly = opener.getAssembly();
    mtzFile = new File(mtzname);
    cifFile = new File(cifname);
    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(structure);
    // read in Fo/sigFo/FreeR
    MTZFilter mtzFilter = new MTZFilter();
    CIFFilter cifFilter = new CIFFilter();
    Crystal crystal = Crystal.checkProperties(properties);
    Resolution resolution = Resolution.checkProperties(properties);
    if (crystal == null || resolution == null) {
        if (mtzname != null) {
            reflectionList = mtzFilter.getReflectionList(mtzFile);
        } else {
            reflectionList = cifFilter.getReflectionList(cifFile);
        }
    } else {
        reflectionList = new ReflectionList(crystal, resolution);
    }
    refinementData = new DiffractionRefinementData(properties, reflectionList);
    if (mtzname != null) {
    // assertTrue(info + " mtz file should be read in without errors",
    // mtzFilter.readFile(mtzFile, reflectionList, refinementData,
    // properties));
    } else {
    // assertTrue(info + " cif file should be read in without errors",
    // cifFilter.readFile(cifFile, reflectionList, refinementData,
    // properties));
    }
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    // associate molecular assembly with the structure, set up forcefield
    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 = new ParallelTeam();
    CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, false);
    crs.computeDensity(refinementData.fc);
    refinementData.setCrystalReciprocalSpace_fc(crs);
    crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, true);
    crs.computeDensity(refinementData.fs);
    refinementData.setCrystalReciprocalSpace_fs(crs);
    ScaleBulkMinimize scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, crs, parallelTeam);
    scaleBulkMinimize.minimize(6, 1.0e-4);
    SigmaAMinimize sigmaAMinimize = new SigmaAMinimize(reflectionList, refinementData, parallelTeam);
    sigmaAMinimize.minimize(7, 2.0e-2);
    SplineMinimize splineMinimize = new SplineMinimize(reflectionList, refinementData, refinementData.spline, SplineEnergy.Type.FOFC);
    splineMinimize.minimize(7, 1e-5);
    crystalStats = new CrystalStats(reflectionList, refinementData);
    scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, refinementData.crs_fs, parallelTeam);
    ScaleBulkEnergy scaleBulkEnergy = scaleBulkMinimize.getScaleBulkEnergy();
    int n = scaleBulkMinimize.getNumberOfVariables();
    double[] x = new double[n];
    double[] g = new double[n];
    scaleBulkMinimize.getCoordinates(x);
    scaleBulkEnergy.energyAndGradient(x, g);
    double delta = 1.0e-4;
    double tolerance = 1.0e-4;
    logger.info(String.format("SCATTER TEST"));
    for (int i = 0; i < 30; i++) {
        long time = -System.nanoTime();
        scaleBulkEnergy.energyAndGradient(x, g);
        time += System.nanoTime();
        logger.info(String.format(" Time %12.8f", time * 1.0e-9));
    }
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) ReflectionList(ffx.crystal.ReflectionList) ForceField(ffx.potential.parameters.ForceField) PDBFilter(ffx.potential.parsers.PDBFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Atom(ffx.potential.bonded.Atom) PotentialsFileOpener(ffx.potential.utils.PotentialsFileOpener) MolecularAssembly(ffx.potential.MolecularAssembly) CIFFilter(ffx.xray.parsers.CIFFilter) File(java.io.File) MTZFilter(ffx.xray.parsers.MTZFilter) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution)

Aggregations

ReflectionList (ffx.crystal.ReflectionList)9 Crystal (ffx.crystal.Crystal)7 Resolution (ffx.crystal.Resolution)7 File (java.io.File)5 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)5 Test (org.junit.Test)5 HKL (ffx.crystal.HKL)4 ParallelTeam (edu.rit.pj.ParallelTeam)3 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)3 MolecularAssembly (ffx.potential.MolecularAssembly)3 Atom (ffx.potential.bonded.Atom)3 IOException (java.io.IOException)3 ComplexNumber (ffx.numerics.ComplexNumber)2 ForceField (ffx.potential.parameters.ForceField)2 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)2 PDBFilter (ffx.potential.parsers.PDBFilter)2 DiffractionRefinementData (ffx.xray.DiffractionRefinementData)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 PotentialsFileOpener (ffx.potential.utils.PotentialsFileOpener)1