1 // Clipper-cad utility.
2 /* (C) 2000 Kevin Cowtan */
3 // This is more of a demo application than a serious version
4 /*
5
6 Documetation:
7
8 This will read several mtz's and combine them into one. It will also
9 flip reflections about reciprocal space, or generate an hkl list onto
10 which data from files can be imported. It will do some spacegroup
11 manipulations, but will not expand from a higher order symmetry to a
12 lower at this point. (Later).
13
14 The application is run by a very simple parser, with operations being
15 performed in the order commands are entered. There is almost no error
16 checking at this point.
17
18
19 COMMANDS:
20
21 cell <a> <b> <c> <alpha> <beta> <gamma>
22 Sets the base crystal cell. If this is omitted, it
23 will be taken from the first inputfile.
24
25 spacegroup <spacegroupname>
26 Sets the base crystal spacegroup. If this is omitted, it
27 will be taken from the first inputfile.
28
29 resolution <resol>
30 Set the resolution limit for import or generation of HKLs.
31
32 makehkls
33 Generates a list of HKLs to the current resolution limit. If this is
34 omitted, the list will be read from the first inputfile.
35
36 inputfile <filename>
37 Open an mtz file for reading.
38
39 import <columnpaths> <hkl_datatype>
40 Import the mtz columns or column group given by <columnpaths> to a
41 hkl_data of type <hkl_datatype>.
42 <hkl_datatype> can be one of:
43 I_sigI, F_sigF, F_sigF_ano, F_phi, Phi_fom, ABCD, Flag
44 <columnpaths> is of the form:
45 /<crystal>/<dataset>/[<column_label_1>,<column_label_2>,...]
46 or
47 /<crystal>/<dataset>/<groupname>
48 Automatic identification of column group types will be implemented
49 in the future.
50
51 move <oldpath> <newpath>
52 More or rename any hkl_data, dataset or crystal
53
54 outputfile <filename>
55 Write all the accumulated data to an output mtz file
56
57
58 EXAMPLES:
59
60 ./ccad << eof
61 inputfile testfile.mtz
62 import /unnamed_crystal1/native/[FP,SIGFP] F_sigF
63 outputfile junk.mtz
64 eof
65
66
67 */
68
69 #include <clipper/clipper.h>
70 #include <clipper/clipper-ccp4.h>
71 #include <stdlib.h>
72 #include <iostream>
73
74
75 using namespace clipper;
76 using namespace clipper::data32;
77
78
79
main()80 int main()
81 {
82 Message::set_message_level(1);
83
84 CSpacegroup spgr( "spgr" );
85 CCell cell( spgr, "cell" );
86 CResolution reso( cell, "reso" );
87 CHKL_info rfl( reso, "ccad" );
88
89 CCP4MTZfile mtzfile;
90
91 bool have_file = false;
92 bool make_hkls = false;
93
94 String line = "";
95
96 // read and parse input lines
97 while ( std::getline( std::cin, line ), !std::cin.eof() ) {
98 std::vector<String> tokens = line.split(" ");
99
100 // set cell
101 if ( tokens[0] == "cell" ) {
102 cell.init( Cell( Cell_descr( tokens[1].f(), tokens[2].f(), tokens[3].f(),
103 tokens[4].f(), tokens[5].f(), tokens[6].f() ) ) );
104 }
105
106 // set spacegroup
107 if ( tokens[0] == "spacegroup" ) {
108 spgr.init( Spacegroup( Spgr_descr( tokens[1] ) ) );
109 }
110
111 // set resolution
112 if ( tokens[0] == "resolution" ) {
113 reso.init( Resolution( ftype(tokens[1].f()) ) );
114 }
115
116 // generate hkls
117 if ( tokens[0] == "makehkls" ) {
118 make_hkls = true;
119 }
120
121 // new input file
122 if ( tokens[0] == "inputfile" ) {
123 if ( have_file ) {
124 mtzfile.close_read(); // close old file
125 } else {
126 mtzfile.open_read( tokens[1] ); // open new file
127 if ( spgr.is_null() ) spgr.init( mtzfile.spacegroup() );
128 if ( cell.is_null() ) cell.init( mtzfile.cell() );
129 if ( reso.is_null() ) reso.init( mtzfile.resolution() );
130 mtzfile.import_hkl_info( rfl, make_hkls ); // read hkls
131 have_file = true;
132 }
133 }
134
135 // import a column list
136 else if ( tokens[0] == "import" ) {
137 if ( !have_file ) exit(1);
138
139 // read the data into a known hkl_data type
140 Container* hkldata;
141 if ( tokens[2] == "I_sigI" ) hkldata = new CHKL_data<I_sigI>( rfl );
142 else if ( tokens[2] == "F_sigF" ) hkldata = new CHKL_data<F_sigF>( rfl );
143 else if (tokens[2]=="F_sigF_ano") hkldata = new CHKL_data<F_sigF_ano>( rfl );
144 else if ( tokens[2] == "F_phi" ) hkldata = new CHKL_data<F_phi>( rfl );
145 else if ( tokens[2] == "Phi_fom") hkldata = new CHKL_data<Phi_fom>( rfl );
146 else if ( tokens[2] == "ABCD" ) hkldata = new CHKL_data<ABCD>( rfl );
147 else if ( tokens[2] == "Flag" ) hkldata = new CHKL_data<Flag>( rfl );
148 hkldata->set_destroyed_with_parent();
149 mtzfile.import_chkl_data( *hkldata, tokens[1] );
150 }
151
152 // move stuff about the tree
153 else if ( tokens[0] == "move" ) {
154 rfl.find_path_ptr( tokens[1] )->move( tokens[2] );
155 }
156
157 // write the data
158 else if ( tokens[0] == "outputfile" ) {
159 if ( have_file ) mtzfile.close_read(); // close old file
160
161 mtzfile.open_write( tokens[1] );
162 mtzfile.export_hkl_info( rfl );
163 // search over crystals, datasets, and lists
164 for ( int i = 0; i < rfl.num_children(); i++ )
165 for ( int j = 0; j < rfl.child(i).num_children(); j++ )
166 for ( int k = 0; k < rfl.child(i).child(j).num_children(); k++ )
167 mtzfile.export_chkl_data( rfl.child(i).child(j).child(k), rfl.child(i).child(j).child(k).path() );
168 mtzfile.close_write();
169 }
170
171 for (int i=0; i<tokens.size(); i++) std::cout << i << ":" << tokens[i] << "\n";
172 rfl.Container::debug();
173 }
174
175 }
176