Search in sources :

Example 1 with Resolution

use of ffx.crystal.Resolution 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 2 with Resolution

use of ffx.crystal.Resolution 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 3 with Resolution

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

Example 4 with Resolution

use of ffx.crystal.Resolution 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 5 with Resolution

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

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