Search in sources :

Example 1 with ReflectionList

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

the class MTZFilterTest method testMTZReflectionList.

@Test
public void testMTZReflectionList() {
    MTZFilter mtzFilter = new MTZFilter();
    ReflectionList tmp = mtzFilter.getReflectionList(mtzFile);
    assertNotNull("mtz file should return a reflection list", tmp);
    assertEquals("reflection list space group", 1, tmp.spaceGroup.number);
    assertEquals("reflection list cell dimension", 29.969, tmp.crystal.a, 0.01);
    assertEquals("reflection list resolution", 1.30, tmp.resolution.resolutionLimit(), 0.01);
}
Also used : ReflectionList(ffx.crystal.ReflectionList) Test(org.junit.Test)

Example 2 with ReflectionList

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

the class MTZFilter method getReflectionList.

/**
 * {@inheritDoc}
 */
@Override
public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) {
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileInputStream fileInputStream;
    DataInputStream dataInputStream;
    try {
        fileInputStream = new FileInputStream(mtzFile);
        dataInputStream = new DataInputStream(fileInputStream);
        byte[] headerOffset = new byte[4];
        byte[] bytes = new byte[80];
        int offset = 0;
        // Eat "MTZ" title.
        dataInputStream.read(bytes, offset, 4);
        String mtzstr = new String(bytes);
        // Header offset.
        dataInputStream.read(headerOffset, offset, 4);
        // Machine stamp.
        dataInputStream.read(bytes, offset, 4);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        int stamp = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt();
        String stampstr = Integer.toHexString(stamp);
        switch(stampstr.charAt(0)) {
            case '1':
            case '3':
                if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) {
                    byteOrder = ByteOrder.BIG_ENDIAN;
                }
                break;
            case '4':
                if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
                    byteOrder = ByteOrder.LITTLE_ENDIAN;
                }
                break;
        }
        byteBuffer = ByteBuffer.wrap(headerOffset);
        int headerOffsetI = byteBuffer.order(byteOrder).getInt();
        // skip to header and parse
        dataInputStream.skipBytes((headerOffsetI - 4) * 4);
        for (Boolean parsing = true; parsing; dataInputStream.read(bytes, offset, 80)) {
            mtzstr = new String(bytes);
            parsing = parseHeader(mtzstr);
        }
    } catch (EOFException e) {
        String message = " MTZ end of file reached.";
        logger.log(Level.WARNING, message, e);
        return null;
    } catch (IOException e) {
        String message = " MTZ IO exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }
    // column identifiers
    foString = sigFoString = rFreeString = null;
    if (properties != null) {
        foString = properties.getString("fostring", null);
        sigFoString = properties.getString("sigfostring", null);
        rFreeString = properties.getString("rfreestring", null);
    }
    h = k = l = fo = sigFo = rFree = -1;
    fPlus = sigFPlus = fMinus = sigFMinus = rFreePlus = rFreeMinus = -1;
    fc = phiC = -1;
    boolean print = false;
    parseColumns(print);
    parseFcColumns(print);
    if (fo < 0 && fPlus < 0 && sigFo < 0 && sigFPlus < 0 && fc < 0 && phiC < 0) {
        logger.info(" The MTZ header contains insufficient information to generate the reflection list.");
        logger.info(" For non-default column labels set fostring/sigfostring in the properties file.");
        return null;
    }
    Column column;
    if (fo > 0) {
        column = (Column) columns.get(fo);
    } else if (fPlus > 0) {
        column = (Column) columns.get(fPlus);
    } else {
        column = (Column) columns.get(fc);
    }
    Dataset dataSet = (Dataset) dataSets.get(column.id - dsetOffset);
    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(format("\n Reading %s\n\n", mtzFile.getName()));
        sb.append(format(" Setting up reflection list based on MTZ file.\n"));
        sb.append(format("  Space group number: %d (name: %s)\n", spaceGroupNum, SpaceGroup.spaceGroupNames[spaceGroupNum - 1]));
        sb.append(format("  Resolution:         %8.3f\n", 0.999999 * resHigh));
        sb.append(format("  Cell:               %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", dataSet.cell[0], dataSet.cell[1], dataSet.cell[2], dataSet.cell[3], dataSet.cell[4], dataSet.cell[5]));
        logger.info(sb.toString());
    }
    Crystal crystal = new Crystal(dataSet.cell[0], dataSet.cell[1], dataSet.cell[2], dataSet.cell[3], dataSet.cell[4], dataSet.cell[5], SpaceGroup.spaceGroupNames[spaceGroupNum - 1]);
    double sampling = 0.6;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 0.6);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);
    return new ReflectionList(crystal, resolution, properties);
}
Also used : ByteOrder(java.nio.ByteOrder) IOException(java.io.IOException) ReflectionList(ffx.crystal.ReflectionList) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) EOFException(java.io.EOFException) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution)

Example 3 with ReflectionList

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

the class CrystalReciprocalSpaceTest method test1N7SPermanent.

/**
 * Test of permanent method, of class CrystalReciprocalSpace.
 */
@Test
public void test1N7SPermanent() {
    String filename = "ffx/xray/structures/1N7S.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());
    PotentialsUtils potutil = new PotentialsUtils();
    MolecularAssembly mola = potutil.open(structure);
    CompositeConfiguration properties = mola.getProperties();
    Crystal crystal = new Crystal(39.767, 51.750, 132.938, 90.00, 90.00, 90.00, "P212121");
    Resolution resolution = new Resolution(1.45);
    ReflectionList reflectionList = new ReflectionList(crystal, resolution);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    mola.finalize(true, mola.getForceField());
    ForceFieldEnergy energy = mola.getPotentialEnergy();
    List<Atom> atomList = mola.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(-828.584, -922.704);
    HKL hkl = reflectionList.getHKL(1, 1, 4);
    ComplexNumber a = refinementData.getFc(hkl.index());
    System.out.println("1 1 4: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("1 1 4 reflection should be correct", -753.4722104328416, a.re(), 0.0001);
    assertEquals("1 1 4 reflection should be correct", -1012.1341308707799, a.im(), 0.0001);
    b.re(-70.4582);
    b.im(-486.142);
    hkl = reflectionList.getHKL(2, 1, 10);
    a = refinementData.getFc(hkl.index());
    System.out.println("2 1 10: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("2 1 10 reflection should be correct", -69.39660884054359, a.re(), 0.0001);
    assertEquals("2 1 10 reflection should be correct", -412.0147625765328, a.im(), 0.0001);
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) 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) File(java.io.File) PotentialsUtils(ffx.potential.utils.PotentialsUtils) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution) Test(org.junit.Test)

Example 4 with ReflectionList

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

the class CIFFilterTest method testCIFFilter3DYC.

@Test
public void testCIFFilter3DYC() {
    String filename = "ffx/xray/structures/3DYC.ent";
    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);
    assertNotNull(" Reflection list should not be null", reflectionList);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    assertTrue(" CIF data not read in correctly", cifFilter.readFile(cifFile, reflectionList, refinementData, properties));
    HKL hkl = reflectionList.getHKL(58, 0, 13);
    assertEquals("58 0 13 F", 99.7, refinementData.getF(hkl.index()), 0.01);
    assertEquals("58 0 13 sigF", 69.7, refinementData.getSigF(hkl.index()), 0.01);
    assertEquals("58 0 13 freeR value", 1, refinementData.freer[hkl.index()]);
    hkl = reflectionList.getHKL(28, 20, 5);
    assertEquals("28 20 5 F", 428.1, refinementData.getF(hkl.index()), 0.01);
    assertEquals("28 20 5 sigF", 10.1, refinementData.getSigF(hkl.index()), 0.01);
    assertEquals("28 20 5 freeR value", 0, 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) Test(org.junit.Test)

Example 5 with ReflectionList

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

the class CIFFilter method getReflectionList.

/**
 * {@inheritDoc}
 */
@Override
public ReflectionList getReflectionList(File cifFile, CompositeConfiguration properties) {
    try {
        BufferedReader br = new BufferedReader(new FileReader(cifFile));
        String string;
        while ((string = br.readLine()) != null) {
            // Reached reflections, break.
            if (string.startsWith("_refln.")) {
                break;
            }
            String[] strArray = string.split("\\s+");
            if (strArray[0].startsWith("_reflns") || strArray[0].startsWith("_cell") || strArray[0].startsWith("_symmetry")) {
                String[] cifArray = strArray[0].split("\\.+");
                switch(Header.toHeader(cifArray[1])) {
                    case d_resolution_high:
                        resHigh = Double.parseDouble(strArray[1]);
                        break;
                    case number_all:
                        nAll = Integer.parseInt(strArray[1]);
                        break;
                    case number_obs:
                        nObs = Integer.parseInt(strArray[1]);
                        break;
                    case length_a:
                        cell[0] = Double.parseDouble(strArray[1]);
                        break;
                    case length_b:
                        cell[1] = Double.parseDouble(strArray[1]);
                        break;
                    case length_c:
                        cell[2] = Double.parseDouble(strArray[1]);
                        break;
                    case angle_alpha:
                        cell[3] = Double.parseDouble(strArray[1]);
                        break;
                    case angle_beta:
                        cell[4] = Double.parseDouble(strArray[1]);
                        break;
                    case angle_gamma:
                        cell[5] = Double.parseDouble(strArray[1]);
                        break;
                    case Int_Tables_number:
                        spacegroupNum = Integer.parseInt(strArray[1]);
                        break;
                    case space_group_name_H_M:
                        String[] spacegroupNameArray = string.split("'+");
                        if (spacegroupNameArray.length > 1) {
                            spacegroupName = spacegroupNameArray[1];
                        } else if (strArray.length > 1) {
                            spacegroupName = strArray[1];
                        }
                        break;
                }
            }
        }
        br.close();
    } catch (IOException e) {
        String message = " CIF IO Exception.";
        logger.log(Level.WARNING, message, e);
        return null;
    }
    if (spacegroupNum < 0 && spacegroupName != null) {
        spacegroupNum = SpaceGroup.spaceGroupNumber(SpaceGroup.pdb2ShortName(spacegroupName));
    }
    if (spacegroupNum < 0 || resHigh < 0 || cell[0] < 0) {
        logger.info(" The CIF header contains insufficient information to generate the reflection list.");
        return null;
    }
    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\nOpening %s\n", cifFile.getName()));
        sb.append(String.format("setting up Reflection List based on CIF:\n"));
        sb.append(String.format("  spacegroup #: %d (name: %s)\n", spacegroupNum, SpaceGroup.spaceGroupNames[spacegroupNum - 1]));
        sb.append(String.format("  resolution: %8.3f\n", 0.999999 * resHigh));
        sb.append(String.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]));
        sb.append(String.format("\n  CIF # HKL (observed): %d\n", nObs));
        sb.append(String.format("  CIF # HKL (all):      %d\n", nAll));
        logger.info(sb.toString());
    }
    Crystal crystal = new Crystal(cell[0], cell[1], cell[2], cell[3], cell[4], cell[5], SpaceGroup.spaceGroupNames[spacegroupNum - 1]);
    double sampling = 1.0 / 1.5;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 1.0 / 1.5);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);
    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) 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