1 #include <clipper/clipper.h>
2 #include <clipper/clipper-ccp4.h>
3 #include <clipper/clipper-cns.h>
4 
5 #include <iostream>
6 
7 
8 using namespace clipper;
9 using namespace clipper::data32;
10 
11 
main(int argc,char ** argv)12 int main(int argc, char** argv)
13 {
14   CCP4MTZfile file;
15 
16   // import an mtz
17   HKL_info mydata;
18   HKL_data<F_sigF> myfsig( mydata );
19   HKL_data<Phi_fom> myphwt( mydata );
20   MTZcrystal xtl;
21   MTZdataset set;
22 
23   file.open_read( argv[1] );
24   file.import_hkl_info( mydata, false );
25   file.import_hkl_data( myfsig, set, xtl, "*/*/[FP SIGFP]" );
26   file.import_hkl_data( myphwt, set, xtl, "*/*/[PHIB FOM]" );
27   file.close_read();
28 
29   CNS_HKLfile cns;
30   cns.open_write( "1.hkl" );
31   cns.export_hkl_info( mydata );
32   cns.export_hkl_data( myfsig );
33   cns.export_hkl_data( myphwt );
34   cns.close_write();
35 
36   HKL_info mydata2( mydata.spacegroup(), mydata.cell(), mydata.resolution() );
37   HKL_data<F_sigF> myfsig2( mydata2 );
38   HKL_data<Phi_fom> myphwt2( mydata2 );
39   cns.open_read( "1.hkl" );
40   cns.import_hkl_info( mydata2 );
41   cns.import_hkl_data( myfsig2 );
42   cns.import_hkl_data( myphwt2 );
43   cns.close_read();
44 
45   cns.open_write( "2.hkl" );
46   cns.export_hkl_info( mydata2 );
47   cns.export_hkl_data( myfsig2 );
48   cns.export_hkl_data( myphwt2 );
49   cns.close_write();
50 
51   HKL_data<data32::F_phi> fphi( mydata );
52   fphi.compute( myfsig, myphwt, data32::Compute_fphi_from_fsigf_phifom() );
53   Grid_sampling grid( mydata.spacegroup(), mydata.cell(), Resolution(8.0) );
54   Xmap<float> xmap1( mydata.spacegroup(), mydata.cell(), grid );
55   Xmap<float> xmap2;
56   xmap1.fft_from( fphi );
57   CNSMAPfile map( mydata.spacegroup() );
58   map.open_write( "1.map" );
59   map.export_xmap( xmap1 );
60   map.close_write();
61 
62   map.open_read( "1.map" );
63   map.import_xmap( xmap2 );
64   map.close_read();
65 
66   map.open_write( "2.map" );
67   map.export_xmap( xmap2 );
68   map.close_write();
69 
70   std::cout << xmap1.spacegroup().symbol_hall() << "\t" << xmap1.grid_sampling().format() << "\n";
71   std::cout << xmap2.spacegroup().symbol_hall() << "\t" << xmap2.grid_sampling().format() << "\n";
72 
73   Xmap<float>::Map_reference_index ix;
74   for ( ix = xmap1.first(); !ix.last(); ix.next() )
75     if ( fabs( xmap1[ix] - xmap2[ix] ) > 0.0001 )
76       std::cout << ix.coord().format() << "\t" << xmap1[ix] << "\t" << xmap2[ix] << "\n";
77 
78 
79   // now check cns vs ccp4 files: get the test files from the EDS
80   /*
81   Xmap<float> x1, x2;
82   CCP4MAPfile f1;
83   f1.open_read( "1ajr.ccp4" );
84   f1.import_xmap( x1 );
85   f1.close_read();
86   CNSMAPfile  f2( x1.spacegroup() );
87   f2.open_read( "1ajr.cns" );
88   f2.import_xmap( x2 );
89   f2.close_read();
90   std::cout << x1.spacegroup().symbol_hall() << "\t" << x1.grid_sampling().format() << "\n";
91   std::cout << x2.spacegroup().symbol_hall() << "\t" << x2.grid_sampling().format() << "\n";
92 
93   for ( ix = x1.first(); !ix.last(); ix.next() )
94     if ( fabs( x1[ix] - x2[ix] ) > 0.0001 )
95       std::cout << ix.coord().format() << "\t" << x1[ix] << "\t" << x2[ix] << "\n";
96   */
97 }
98