Search in sources :

Example 11 with HKL

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

the class CNSFilter method getResolution.

/**
 * {@inheritDoc}
 */
@Override
public double getResolution(File cnsFile, Crystal crystal) {
    double res = Double.POSITIVE_INFINITY;
    try {
        BufferedReader br = new BufferedReader(new FileReader(cnsFile));
        HKL hkl = new HKL();
        String string;
        while ((string = br.readLine()) != null) {
            String[] strArray = string.split("\\s+");
            for (int i = 0; i < strArray.length; i++) {
                if (strArray[i].toLowerCase().startsWith("inde")) {
                    if (i < strArray.length - 3) {
                        int ih = parseInt(strArray[i + 1]);
                        int ik = parseInt(strArray[i + 2]);
                        int il = parseInt(strArray[i + 3]);
                        hkl.h(ih);
                        hkl.k(ik);
                        hkl.l(il);
                        res = min(res, Crystal.res(crystal, hkl));
                    }
                }
            }
        }
    } catch (IOException e) {
        String message = " CNS IO Exception.";
        logger.log(Level.WARNING, message, e);
        return -1.0;
    }
    return res;
}
Also used : BufferedReader(java.io.BufferedReader) HKL(ffx.crystal.HKL) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 12 with HKL

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

the class CNSFilter method readFile.

/**
 * {@inheritDoc}
 */
@Override
public boolean readFile(File cnsFile, ReflectionList reflectionList, DiffractionRefinementData refinementData, CompositeConfiguration properties) {
    int nRead, nRes, nIgnore, nFriedel, nCut;
    boolean transpose = false;
    StringBuilder sb = new StringBuilder();
    sb.append(format("\n Opening %s\n", cnsFile.getName()));
    if (refinementData.rfreeflag < 0) {
        refinementData.setFreeRFlag(1);
        sb.append(format(" Setting R free flag to CNS default: %d\n", refinementData.rfreeflag));
    }
    try {
        BufferedReader br = new BufferedReader(new FileReader(cnsFile));
        boolean hasHKL, hasFo, hasSigFo, hasFree;
        int ih, ik, il, free;
        double fo, sigFo;
        hasHKL = hasFo = hasSigFo = hasFree = false;
        ih = ik = il = free = -1;
        fo = sigFo = -1.0;
        // Check if HKLs need to be transposed or not.
        HKL mate = new HKL();
        int nPosIgnore = 0;
        int nTransIgnore = 0;
        String string;
        while ((string = br.readLine()) != null) {
            String[] strArray = string.split("\\s+");
            for (int i = 0; i < strArray.length; i++) {
                if (strArray[i].toLowerCase().startsWith("inde")) {
                    if (i < strArray.length - 3) {
                        ih = Integer.parseInt(strArray[i + 1]);
                        ik = Integer.parseInt(strArray[i + 2]);
                        il = Integer.parseInt(strArray[i + 3]);
                        boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, false);
                        HKL hklpos = reflectionList.getHKL(mate);
                        if (hklpos == null) {
                            nPosIgnore++;
                        }
                        friedel = reflectionList.findSymHKL(ih, ik, il, mate, true);
                        HKL hkltrans = reflectionList.getHKL(mate);
                        if (hkltrans == null) {
                            nTransIgnore++;
                        }
                    }
                }
            }
        }
        if (nPosIgnore > nTransIgnore) {
            transpose = true;
        }
        // column identifiers
        foString = sigFoString = rFreeString = null;
        if (properties != null) {
            foString = properties.getString("fostring", null);
            sigFoString = properties.getString("sigfostring", null);
            rFreeString = properties.getString("rfreestring", null);
        }
        // reopen to start at beginning
        br = new BufferedReader(new FileReader(cnsFile));
        // read in data
        double[][] anofSigF = new double[refinementData.n][4];
        for (int i = 0; i < refinementData.n; i++) {
            anofSigF[i][0] = anofSigF[i][1] = anofSigF[i][2] = anofSigF[i][3] = Double.NaN;
        }
        nRead = nRes = nIgnore = nFriedel = nCut = 0;
        while ((string = br.readLine()) != null) {
            String[] strArray = string.split("\\s+");
            for (int i = 0; i < strArray.length; i++) {
                if (strArray[i].toLowerCase().startsWith("inde")) {
                    if (hasHKL && hasFo && hasSigFo && hasFree) {
                        boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, transpose);
                        HKL hkl = reflectionList.getHKL(mate);
                        if (hkl != null) {
                            if (refinementData.fsigfcutoff > 0.0 && (fo / sigFo) < refinementData.fsigfcutoff) {
                                nCut++;
                            } else if (friedel) {
                                anofSigF[hkl.index()][2] = fo;
                                anofSigF[hkl.index()][3] = sigFo;
                                nFriedel++;
                            } else if (!friedel) {
                                anofSigF[hkl.index()][0] = fo;
                                anofSigF[hkl.index()][1] = sigFo;
                            }
                            refinementData.setFreeR(hkl.index(), free);
                            nRead++;
                        } else {
                            HKL tmp = new HKL(ih, ik, il);
                            if (!reflectionList.resolution.inInverseResSqRange(Crystal.invressq(reflectionList.crystal, tmp))) {
                                nRes++;
                            } else {
                                nIgnore++;
                            }
                        }
                    }
                    hasHKL = false;
                    hasFo = false;
                    hasSigFo = false;
                    hasFree = false;
                    if (i < strArray.length - 3) {
                        ih = parseInt(strArray[i + 1]);
                        ik = parseInt(strArray[i + 2]);
                        il = parseInt(strArray[i + 3]);
                        hasHKL = true;
                    }
                }
                if (strArray[i].toLowerCase().startsWith("fobs=") || strArray[i].equalsIgnoreCase(foString + "=")) {
                    fo = parseDouble(strArray[i + 1]);
                    hasFo = true;
                }
                if (strArray[i].toLowerCase().startsWith("sigma=") || strArray[i].equalsIgnoreCase(sigFoString + "=")) {
                    sigFo = parseDouble(strArray[i + 1]);
                    hasSigFo = true;
                }
                if (strArray[i].toLowerCase().startsWith("test=") || strArray[i].equalsIgnoreCase(rFreeString + "=")) {
                    free = parseInt(strArray[i + 1]);
                    hasFree = true;
                }
            }
        }
        br.close();
        // Set up fsigf from F+ and F-.
        refinementData.generate_fsigf_from_anofsigf(anofSigF);
    } catch (IOException e) {
        String message = "CNS IO Exception.";
        logger.log(Level.WARNING, message, e);
        return false;
    }
    if (logger.isLoggable(Level.INFO)) {
        sb.append(format(" HKL read in:                             %d\n", nRead));
        sb.append(format(" HKL read as friedel mates:               %d\n", nFriedel));
        sb.append(format(" HKL not read in (too high resolution):   %d\n", nRes));
        sb.append(format(" HKL not read in (not in internal list?): %d\n", nIgnore));
        sb.append(format(" HKL not read in (F/sigF cutoff):         %d\n", nCut));
        sb.append(format(" HKL in internal list:                    %d\n", reflectionList.hkllist.size()));
        logger.info(sb.toString());
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) HKL(ffx.crystal.HKL) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 13 with HKL

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

the class MTZFilter method readFcs.

/**
 * Read the structure factors.
 *
 * @param mtzFile
 * @param reflectionList
 * @param fcData
 * @param properties
 * @return
 */
public boolean readFcs(File mtzFile, ReflectionList reflectionList, DiffractionRefinementData fcData, CompositeConfiguration properties) {
    int nRead, nIgnore, nRes, nFriedel, nCut;
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileInputStream fileInputStream;
    DataInputStream dataInputStream;
    StringBuilder sb = new StringBuilder();
    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 mtzString = null;
        // 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 stampString = Integer.toHexString(stamp);
        switch(stampString.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)) {
            mtzString = new String(bytes);
            parsing = parseHeader(mtzString);
        }
        // Column identifiers.
        fc = phiC = fs = phiS = -1;
        boolean print = true;
        parseFcColumns(print);
        if (h < 0 || k < 0 || l < 0) {
            String message = " Fatal error in MTZ file - no H K L indexes?\n";
            logger.log(Level.SEVERE, message);
            return false;
        }
        // Reopen to start at beginning.
        fileInputStream = new FileInputStream(mtzFile);
        dataInputStream = new DataInputStream(fileInputStream);
        // Skip initial header.
        dataInputStream.skipBytes(80);
        float[] data = new float[nColumns];
        HKL mate = new HKL();
        // Read in data.
        ComplexNumber complexNumber = new ComplexNumber();
        nRead = nIgnore = nRes = nFriedel = nCut = 0;
        for (int i = 0; i < nReflections; i++) {
            for (int j = 0; j < nColumns; j++) {
                dataInputStream.read(bytes, offset, 4);
                byteBuffer = ByteBuffer.wrap(bytes);
                data[j] = byteBuffer.order(byteOrder).getFloat();
            }
            int ih = (int) data[h];
            int ik = (int) data[k];
            int il = (int) data[l];
            boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, false);
            HKL hkl = reflectionList.getHKL(mate);
            if (hkl != null) {
                if (fc > 0 && phiC > 0) {
                    complexNumber.re(data[fc] * cos(toRadians(data[phiC])));
                    complexNumber.im(data[fc] * sin(toRadians(data[phiC])));
                    fcData.setFc(hkl.index(), complexNumber);
                }
                if (fs > 0 && phiS > 0) {
                    complexNumber.re(data[fs] * cos(toRadians(data[phiS])));
                    complexNumber.im(data[fs] * sin(toRadians(data[phiS])));
                    fcData.setFs(hkl.index(), complexNumber);
                }
                nRead++;
            } else {
                HKL tmp = new HKL(ih, ik, il);
                if (!reflectionList.resolution.inInverseResSqRange(Crystal.invressq(reflectionList.crystal, tmp))) {
                    nRes++;
                } else {
                    nIgnore++;
                }
            }
        }
        if (logger.isLoggable(Level.INFO)) {
            sb.append(format(" MTZ file type (machine stamp): %s\n", stampString));
            sb.append(format(" Fc HKL read in:                             %d\n", nRead));
            sb.append(format(" Fc HKL read as friedel mates:               %d\n", nFriedel));
            sb.append(format(" Fc HKL NOT read in (too high resolution):   %d\n", nRes));
            sb.append(format(" Fc HKL NOT read in (not in internal list?): %d\n", nIgnore));
            sb.append(format(" Fc HKL NOT read in (F/sigF cutoff):         %d\n", nCut));
            sb.append(format(" HKL in internal list:                       %d\n", reflectionList.hkllist.size()));
            logger.info(sb.toString());
        }
    } catch (EOFException e) {
        String message = " MTZ end of file reached.";
        logger.log(Level.WARNING, message, e);
        return false;
    } catch (IOException e) {
        String message = " MTZ IO Exception.";
        logger.log(Level.WARNING, message, e);
        return false;
    }
    return true;
}
Also used : HKL(ffx.crystal.HKL) ByteOrder(java.nio.ByteOrder) ComplexNumber(ffx.numerics.ComplexNumber) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) EOFException(java.io.EOFException)

Example 14 with HKL

use of ffx.crystal.HKL 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 15 with HKL

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

Aggregations

HKL (ffx.crystal.HKL)27 ComplexNumber (ffx.numerics.ComplexNumber)8 IOException (java.io.IOException)6 Test (org.junit.Test)6 ReflectionSpline (ffx.crystal.ReflectionSpline)5 ReflectionList (ffx.crystal.ReflectionList)4 BufferedReader (java.io.BufferedReader)4 File (java.io.File)4 FileReader (java.io.FileReader)4 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)4 Crystal (ffx.crystal.Crystal)3 Resolution (ffx.crystal.Resolution)3 ByteBuffer (java.nio.ByteBuffer)3 ByteOrder (java.nio.ByteOrder)3 ParallelTeam (edu.rit.pj.ParallelTeam)2 SymOp (ffx.crystal.SymOp)2 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)2 MolecularAssembly (ffx.potential.MolecularAssembly)2 Atom (ffx.potential.bonded.Atom)2 DiffractionRefinementData (ffx.xray.DiffractionRefinementData)2