1
// Clipper app to convert HL coeffs to phi/fom or back
2
/* Copyright 2003-2004 Kevin Cowtan & University of York all rights reserved */
4
#include <clipper/clipper.h>
5
#include <clipper/clipper-ccp4.h>
8
int main( int argc, char** argv )
10
CCP4Program prog( "chltofom", "0.1", "$Date: 2004/05/01" );
13
clipper::String title;
14
clipper::String ipfile = "NONE";
15
clipper::String ipcolf = "NONE";
16
clipper::String ipcolh = "NONE";
17
clipper::String ipcolp = "NONE";
18
clipper::String opfile = "hltofom.mtz";
19
clipper::String opcol = "hltofom";
22
CCP4CommandInput args( argc, argv, true );
24
while ( ++arg < args.size() ) {
25
if ( args[arg] == "-title" ) {
26
if ( ++arg < args.size() ) title = args[arg];
27
} else if ( args[arg] == "-mtzin" ) {
28
if ( ++arg < args.size() ) ipfile = args[arg];
29
} else if ( args[arg] == "-mtzout" ) {
30
if ( ++arg < args.size() ) opfile = args[arg];
31
} else if ( args[arg] == "-colin-hl" ) {
32
if ( ++arg < args.size() ) ipcolh = args[arg];
33
} else if ( args[arg] == "-colin-phifom" ) {
34
if ( ++arg < args.size() ) ipcolp = args[arg];
35
} else if ( args[arg] == "-colin-fo" ) {
36
if ( ++arg < args.size() ) ipcolf = args[arg];
37
} else if ( args[arg] == "-colout" ) {
38
if ( ++arg < args.size() ) opcol = args[arg];
40
std::cout << "Unrecognized:\t" << args[arg] << "\n";
44
if ( args.size() <= 1 ) {
45
std::cout << "Usage: chltofom\n\t-mtzin <filename>\n\t-mtzout <filename>\n\t-colin-fo <colpath>\n\t-colin-hl <colpath>\n\t-colin-phifom <colpath>\n\t-colout <colpath>\nIf -colin-hl is specified, conversion is ABCD->phi/fom.\nIf -colin-phifom is specified, conversion is phi/fom->ABCD.\nIf -colin-fo is specified, weighted map coefficients are calculated in addition.\nIf no FOM is present, it is set to 0.99.\n";
50
clipper::CCP4MTZfile mtzin, mtzout;
51
clipper::HKL_info hkls;
54
mtzin.open_read( ipfile );
55
mtzin.import_hkl_info( hkls );
56
clipper::HKL_data<clipper::data32::Phi_fom> phiw( hkls );
57
clipper::HKL_data<clipper::data32::ABCD> abcd( hkls );
58
clipper::HKL_data<clipper::data32::F_sigF> fsig( hkls );
59
clipper::HKL_data<clipper::data32::F_phi> fphi( hkls );
60
if ( ipcolh != "NONE" ) mtzin.import_hkl_data( abcd, ipcolh );
61
if ( ipcolp != "NONE" ) mtzin.import_hkl_data( phiw, ipcolp );
62
if ( ipcolf != "NONE" ) mtzin.import_hkl_data( fsig, ipcolf );
63
clipper::String opbase = mtzin.assigned_paths()[0];
64
if ( opcol == "" ) opcol = opbase.substr( 0, opbase.find(".") );
65
else if ( opcol[0] != '/' ) opcol = opbase.notail()+"/"+opcol;
67
mtzout.open_append( ipfile, opfile );
68
// compute phi+fom from abcd
69
if ( ipcolh != "NONE" ) {
70
phiw.compute( abcd, clipper::data32::Compute_phifom_from_abcd() );
71
mtzout.export_hkl_data( phiw, opcol );
73
// compute abcd from phi+fom
74
if ( ipcolp != "NONE" ) {
75
// if weights absent, then set to 0.99
76
clipper::HKL_data_base::HKL_reference_index ih;
77
for ( ih = phiw.first(); !ih.last(); ih.next() )
78
if ( !clipper::Util::is_nan( phiw[ih].fom() ) ) break;
80
for ( ih = phiw.first(); !ih.last(); ih.next() ) phiw[ih].fom() = 0.99;
81
abcd.compute( phiw, clipper::data32::Compute_abcd_from_phifom() );
82
mtzout.export_hkl_data( abcd, opcol );
84
// compute weighted F from F + phi
85
if ( ipcolf != "NONE" ) {
86
fphi.compute( fsig, phiw, clipper::data32::Compute_fphi_from_fsigf_phifom() );
87
mtzout.export_hkl_data( fphi, opcol );
89
mtzout.close_append();