class TestDensityMapReader(test.Case):
    def setUp(self):

        super(TestDensityMapReader, self).setUp()

        self.file = self.config.getTestFile('1C3W_10.mrc')
        self.reader = DensityMapReader(self.file)
        self.rawheader = None

        with open(self.file, 'rb') as stream:
            self.rawheader = self.reader._rawheader(stream)

    def testReadRawHeader(self):
        self.assertEqual(len(self.rawheader), DensityMapReader.HEADER_SIZE)

    def testReadHeader(self):

        density = self.reader.read_header()

        self.assertEqual(density.data, None)
        self.assertEqual(density.header, self.rawheader)
        self.assertEqual(density.origin, [-36.0, -36.0, -36.0])
        self.assertEqual(density.shape, (72, 72, 72))
        self.assertEqual(density.spacing, (1.0, 1.0, 1.0))

    def testRead(self):

        density = self.reader.read()

        self.assertNotEqual(density.data, None)
        self.assertEqual(density.header, self.rawheader)
        self.assertEqual(density.origin, [-36.0, -36.0, -36.0])
        self.assertEqual(density.shape, (72, 72, 72))
        self.assertEqual(density.spacing, (1.0, 1.0, 1.0))
class TestDensityMapWriter(test.Case):
    def setUp(self):

        super(TestDensityMapWriter, self).setUp()

        self.file = self.config.getTestFile('1C3W_10.mrc')
        self.writer = DensityMapWriter()
        self.reader = DensityMapReader(self.file)
        self.density = self.reader.read()

    def testWriteDensity(self):

        with self.config.getTempStream(mode='b') as temp:
            with open(self.file, 'rb') as source:
                self.writer.write(temp, self.density)
                temp.flush()
                if temp.content() != source.read():
                    self.fail('binary strings differ')

    def testReconstructHeader(self):

        raw = self.density.header
        self.density.header = None

        new = self.writer.reconstruct_header(self.density)

        original = self.reader._inspect(raw, ByteOrder.NATIVE)
        generated = self.reader._inspect(new, ByteOrder.NATIVE)

        for o, g in zip(original, generated):
            self.assertAlmostEqual(o, g, places=4)
    def setUp(self):

        super(TestDensityMapWriter, self).setUp()

        self.file = self.config.getTestFile('1C3W_10.mrc')
        self.writer = DensityMapWriter()
        self.reader = DensityMapReader(self.file)
        self.density = self.reader.read()
    def setUp(self):

        super(TestDensityMapReader, self).setUp()

        self.file = self.config.getTestFile('1C3W_10.mrc')
        self.reader = DensityMapReader(self.file)
        self.rawheader = None

        with open(self.file, 'rb') as stream:
            self.rawheader = self.reader._rawheader(stream)
示例#5
0
    def run(self):

        writer = DensityMapWriter()

        self.log('Reading input density map...')
        try:
            input = DensityMapReader(self.args.mapfile).read()
            embd = Deconvolution(input.data, self.args.psf_size)

        except DensityMapFormatError as e:
            msg = 'Error reading input MRC file: {0}'.format(e)
            DeconvolutionApp.exit(msg, code=ExitCodes.INVALID_DATA)

        self.log('Running {0} iterations...'.format(self.args.iterations))
        self.log(' Iteration             Loss Correlation  Output')

        for i in range(1, self.args.iterations + 1):
            embd.run_once()

            if i % self.args.output_frequency == 0:
                output = OutputPathBuilder(self.args, i)

                density = DensityInfo(embd.data,
                                      None,
                                      None,
                                      header=input.header)
                writer.write_file(output.fullpath, density)

                self.log('{0:>9}.  {1:15.2f}  {2:10.4f}  {3}'.format(
                    i, embd.loss, embd.correlation, output.filename))

        self.log('Done: {0}.'.format(output.fullpath))