00001
00002
00003
00004
00005 #ifndef POINTLESS_HEADER
00006 #define POINTLESS_HEADER
00007
00008 #include <vector>
00009 #include "io_files.hh"
00010 #include "normalise.hh"
00011 #include "hkl_unmerge.hh"
00012 #include "score_datatypes.hh"
00013 #include "range.hh"
00014 #include "Output.hh"
00015 #include "pgscore.hh"
00016
00017 using namespace scala;
00018
00019 enum PointlessTask {NOTASK, COPY, LAUE, REFERENCE, CENTRE};
00020
00021 class PointlessStatus {
00022 public:
00023
00024 PointlessStatus () : success(false), NumHKLIN(0),
00025 IsHKLOUT(false) {
00026 task = NOTASK;
00027 HKLrefFileType = NONE;
00028 }
00029 PointlessStatus (const bool& ssuccess, const int& numhklin,
00030 const scala::RefListType& reftype, const bool& ishklout,
00031 const PointlessTask& Task)
00032 : success(ssuccess), NumHKLIN(numhklin), HKLrefFileType(reftype),
00033 IsHKLOUT(ishklout), task(Task) {}
00034
00035 bool Success() const { return success;}
00036
00037 private:
00038 bool success;
00039 int NumHKLIN;
00040 scala::RefListType HKLrefFileType;
00041 bool IsHKLOUT;
00042 PointlessTask task;
00043 };
00044
00045
00046 std::vector<IsPair> NullStats(hkl_unmerge_list& ref_list,
00047 const ResoRange& ResRange,
00048 const Normalise& NormRes,
00049 double& ECC0,
00050 phaser_io::Output& output);
00051
00052
00053 template<class T> std::vector<T> Score_Pairs(const std::vector<IsPair>& pair_list,
00054 const int& Ngroup)
00055
00056
00057
00058
00059
00060
00061
00062
00063 {
00064 std::vector<T> sc_group;
00065 T sc;
00066 const float w = 1.0;
00067
00068 int k = -1;
00069 for (int i=0;i<pair_list.size();i++) {
00070 if (++k%Ngroup == 0) {
00071 if (i > 0) {
00072 sc_group.push_back(sc);
00073 }
00074 sc.zero();
00075 k = 0;
00076 }
00077 sc.add(pair_list[i].Is1(), pair_list[i].Is2());
00078 }
00079 return sc_group;
00080 }
00081
00082 template<class T> RPair MeanScore(const std::vector<T>& sc_list)
00083
00084
00085 {
00086 int n = sc_list.size();
00087 double sum_sc = 0.0;
00088 double sum_sc2 = 0.0;
00089 double sc;
00090 double sd;
00091 int count = 0;
00092
00093 if (n<1) return RPair(0.0,0.0);
00094 if (n==1) {
00095 sc = sc_list[0].result().val;
00096 count = sc_list[0].result().count;
00097 sd = 0.0;
00098 } else {
00099 for (int i = 0;i<n;i++) {
00100 sc = sc_list[i].result().val;
00101 sum_sc += sc;
00102 sum_sc2 += sc*sc;
00103 count += sc_list[i].result().count;
00104 }
00105
00106 sc = sum_sc/double(n);
00107
00108 sd = sqrt((sum_sc2 - double(n)*sc*sc)/double(n-1));
00109 }
00110
00111 return RPair(sc, sd);
00112 }
00113
00114 template <class T> double FitScoreSig(const std::vector<IsPair>& pair_list)
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 {
00127 std::vector<T> SC_group;
00128 int Npairs = pair_list.size();
00129
00130
00131 int MinNumGroup = 10;
00132 int MaxNgroup = Min(Npairs/MinNumGroup, 200);
00133 int MinNgroup = Min(5, MaxNgroup);
00134
00135 if(MaxNgroup-MinNgroup < 4) {return 0.0;}
00136
00137 LinearFit SigFunction;
00138 const float w = 1.0;
00139
00140 for (int Ngroup=MinNgroup;Ngroup<=MaxNgroup;Ngroup++) {
00141 SC_group = Score_Pairs<T>(pair_list, Ngroup);
00142
00143 RPair SCmnsd = MeanScore<T>(SC_group);
00144
00145 SigFunction.add(1.0f/sqrt(float(Ngroup)), SCmnsd.second, w);
00146 }
00147 return SigFunction.slope();
00148 }
00149
00150 std::vector<SetScores> MergeSym(hkl_unmerge_list& ref_list,
00151 const ResoRange& ResRange,
00152 const Normalise& NormRes,
00153 const Chirality& ChiralFlag,
00154 int& maxMult, const int& reducedMult);
00155
00156 std::vector<SCsignificance> CCsum(const std::vector<SetScores>& scores);
00157
00158
00159
00160 double EstimateECC(const double& SigFac, const double& ECC0,
00161 const SCsignificance& SCsig1);
00162
00163 template <class T> void ScoreSig(const double& SigFac, const double& ECC,
00164 std::vector<SCsignificance>& SCsig)
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 {
00178 const int MaxGroup = 200;
00179
00180 if (SCsig.size() == 0) return;
00181
00182 for (int i=0;i<SCsig.size();i++) {
00183 int Ngroup = Min(MaxGroup, SCsig[i].Nsample());
00184 if (Ngroup > 2) {
00185 float SD = SigFac/sqrt(float(Ngroup));
00186 SCsig[i].SetUnrSC(SD);
00187
00188 float SDrel = SD;
00189 SCsig[i].SetRelSC(SDrel);
00190 SCsig[i].SetTrueScore(ECC);
00191 SCsig[i].SetScoreRange(-1.0, +1.0);
00192 }
00193 }
00194 }
00195
00196 std::vector<PGscore> ScoreSubGroups(const hkl_symmetry& Symmetry,
00197 const hkl_symmetry& OrigSymm,
00198 const RefListType& HklinIsMerged,
00199 const std::string& OrigName,
00200 const Scell& OriginalCell,
00201 const ReindexOp& reindex_op,
00202 const double& CCsigFac,
00203 const double& ECC,
00204 const std::vector<SetScores>& scores,
00205 const std::vector<SCsignificance>& CCsig,
00206 const int& AllowI2);
00207
00208 void SetConfidenceScores(std::vector<PGscore>& SGscores);
00209
00210
00211 #endif