Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

cmtzlib.h

Go to the documentation of this file.
00001 /*
00002      cmtzlib.h: header file for cmtzlib.c
00003      Copyright (C) 2001  CCLRC, Martyn Winn
00004 
00005      This library is free software and is distributed under the terms and
00006      conditions of the CCP4 licence agreement as `Part 0' (Annex 2)
00007      software, which is version 2.1 of the GNU Lesser General Public
00008      Licence (LGPL) with the following additional clause:
00009 
00010         `You may also combine or link a "work that uses the Library" to
00011         produce a work containing portions of the Library, and distribute
00012         that work under terms of your choice, provided that you give
00013         prominent notice with each copy of the work that the specified
00014         version of the Library is used in it, and that you include or
00015         provide public access to the complete corresponding
00016         machine-readable source code for the Library including whatever
00017         changes were used in the work. (i.e. If you make changes to the
00018         Library you must distribute those, but you do not need to
00019         distribute source or object code to those portions of the work
00020         not covered by this licence.)'
00021 
00022      Note that this clause grants an additional right and does not impose
00023      any additional restriction, and so does not affect compatibility
00024      with the GNU General Public Licence (GPL). If you wish to negotiate
00025      other terms, please contact the maintainer.
00026 
00027      You can redistribute it and/or modify the library under the terms of
00028      the GNU Lesser General Public License as published by the Free Software
00029      Foundation; either version 2.1 of the License, or (at your option) any
00030      later version.
00031 
00032      This library is distributed in the hope that it will be useful, but
00033      WITHOUT ANY WARRANTY; without even the implied warranty of
00034      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035      Lesser General Public License for more details.
00036 
00037      You should have received a copy of the CCP4 licence and/or GNU
00038      Lesser General Public License along with this library; if not, write
00039      to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040      The GNU Lesser General Public can also be obtained by writing to the
00041      Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042      MA 02111-1307 USA
00043 */
00044 
00129 #ifndef __CMTZLib__
00130 #define __CMTZLib__
00131 
00132 static char rcsidhm[100] = "$Id: cmtzlib_8h-source.html,v 1.8 2004/07/05 14:36:56 mdw Exp $";
00133 
00134 /* defines CCP4::CCP4File */
00135 #include "ccp4_utils.h"
00136 
00137 #ifdef  __cplusplus
00138 namespace CMtz {
00139 extern "C" {
00140 typedef CCP4::CCP4File CCP4File;
00141 #endif
00142 
00143 /* needs to be here for C++ to use CCP4File typedef */
00144 #include "mtzdata.h"
00145 
00146 /**** MTZ i/o ****/
00147 
00154 MTZ *MtzGet(const char *logname, int read_refs);
00155 
00162 int MtzRrefl(CCP4File *filein, int ncol, float *refldata);
00163 
00170 int MtzPut(MTZ *mtz, const char *logname);
00171 
00176 CCP4File *MtzOpenForWrite(const char *logname);
00177 
00185 int MtzWhdrLine(CCP4File *fileout, int nitems, char buffer[]);
00186 
00194 int MtzWrefl(CCP4File *fileout, int ncol, float *refldata);
00195 
00202 int MtzDeleteRefl(MTZ *mtz, int iref);
00203 
00204 /**** Memory allocation ****/
00205 
00217 MTZ *MtzMalloc(int nxtal, int nset[]);
00218 
00223 int MtzFree(MTZ *mtz);
00224 
00231 MTZCOL *MtzMallocCol(MTZ *mtz, int nref);
00232 
00237 int MtzFreeCol(MTZCOL *col);
00238 
00242 MTZBAT *MtzMallocBatch(void);
00243 
00248 int MtzFreeBatch(MTZBAT *batch);
00249   
00254 char *MtzCallocHist(int nhist);
00255 
00260 int MtzFreeHist(char *hist);
00261 
00267 void MtzMemTidy(void);
00268 
00269 /**** Header operations ****/
00270   
00275 int MtzNbat(const MTZ *mtz);
00276 
00281 int MtzNref(const MTZ *mtz);
00282 
00287 int MtzSpacegroupNumber(const MTZ *mtz);
00288 
00296 int MtzResLimits(const MTZ *mtz, float *minres, float *maxres);
00297 
00298 /**** Crystal operations ****/
00299 
00304 int MtzNxtal(const MTZ *mtz);
00305 
00310 int MtzNumActiveXtal(const MTZ *mtz);
00311 
00316 MTZXTAL **MtzXtals(MTZ *mtz);
00317 
00323 MTZXTAL *MtzIxtal(const MTZ *mtz, const int ixtal);
00324 
00331 char *MtzXtalPath(const MTZXTAL *xtal);
00332 
00338 MTZXTAL *MtzXtalLookup(const MTZ *mtz, const char *label);
00339 
00347 MTZXTAL *MtzAddXtal(MTZ *mtz, const char *xname, const char *pname,
00348                   const float cell[6]);
00349 
00354 int MtzNsetsInXtal(const MTZXTAL *xtal);
00355 
00360 int MtzNumActiveSetsInXtal(const MTZ *mtz, const MTZXTAL *xtal);
00361 
00367 MTZSET **MtzSetsInXtal(MTZXTAL *xtal);
00368 
00375 MTZSET *MtzIsetInXtal(const MTZXTAL *xtal, const int iset);
00376 
00377 /**** Dataset operations ****/
00378 
00383 int MtzNset(const MTZ *mtz);
00384 
00389 int MtzNumActiveSet(const MTZ *mtz);
00390 
00398 MTZXTAL *MtzSetXtal(const MTZ *mtz, const MTZSET *set);
00399 
00408 char *MtzSetPath(const MTZ *mtz, const MTZSET *set);
00409 
00416 MTZSET *MtzSetLookup(const MTZ *mtz, const char *label);
00417 
00425 MTZSET *MtzAddDataset(MTZ *mtz, MTZXTAL *xtl, const char *dname,
00426                     const float wavelength);
00427 
00434 int MtzNcolsInSet(const MTZSET *set);
00435 
00440 int MtzNumActiveColsInSet(const MTZSET *set);
00441 
00447 int MtzNumSourceColsInSet(const MTZSET *set);
00448 
00454 int MtzNbatchesInSet(const MTZ *mtz, const MTZSET *set);
00455 
00461 MTZCOL **MtzColsInSet(MTZSET *set);
00462 
00470 MTZCOL *MtzIcolInSet(const MTZSET *set, const int icol);
00471 
00472 /**** Column operations ****/
00473 
00481 MTZCOL *MtzAddColumn(MTZ *mtz, MTZSET *set, const char *label,
00482                    const char *type);
00483 
00488 int MtzAssignHKLtoBase(MTZ *mtz);
00489 
00502 int MtzAssignColumn(MTZ *mtz, MTZCOL *col, const char crystal_name[],  
00503              const char dataset_name[]);
00504 
00511 int MtzToggleColumn(MTZCOL *col);
00512 
00519 MTZSET  *MtzColSet(const MTZ *mtz, const MTZCOL *col);
00520 
00525 int MtzNcol(const MTZ *mtz);
00526   
00531 int MtzNumActiveCol(const MTZ *mtz);
00532   
00538 int MtzNumSourceCol(const MTZ *mtz);
00539 
00547 char *MtzColPath(const MTZ *mtz, const MTZCOL *col);
00548 
00555 int MtzRJustPath(char *path, const char *partial, const int njust);
00556 
00562 int MtzPathMatch(const char *path1, const char *path2);
00563 
00569 MTZCOL *MtzColLookup(const MTZ *mtz, const char *label);
00570 
00575 char *MtzColType(MTZCOL *col);
00576 
00582 void MtzDebugHierarchy(const MTZ *mtz);
00583 
00591 int MtzListColumn(const MTZ *mtz, char clabs[][31], char ctyps[][3], int csetid[]);
00592 
00600 int MtzListInputColumn(const MTZ *mtz, char clabs[][31], char ctyps[][3], int csetid[]);
00601 
00602 /**** helper functions ****/
00603 
00612 int MtzFindInd(const MTZ *mtz, int *ind_xtal, int *ind_set, int ind_col[3]);
00613 
00620 float MtzInd2reso(const int in[3], const double coefhkl[6]);
00621 
00627 int MtzHklcoeffs(const float cell[6], double coefhkl[6]);
00628 
00635 int MtzArrayToBatch(const int *intbuf, const float *fltbuf, MTZBAT *batch);
00636 
00643 int MtzBatchToArray(MTZBAT *batch, int *intbuf, float *fltbuf);
00644 
00653 MTZBAT *sort_batches(MTZBAT *batch, int numbat);
00654 
00655 /**** pseudo-mtzlib routines ****/
00656 
00663 int ccp4_lrtitl(const MTZ *mtz, char *title);
00664 
00671 int ccp4_lrhist(const MTZ *mtz, char history[][MTZRECORDLENGTH], int nlines);
00672 
00678 int ccp4_lrsort(const MTZ *mtz, int isort[5]);
00679 
00686 int ccp4_lrbats(const MTZ *mtz, int *nbatx, int batchx[]);
00687 
00693 int ccp4_lrcell(const MTZXTAL *xtl, float cell[]);
00694 
00704 int ccp4_lrsymi(const MTZ *mtz, int *nsympx, char *ltypex, int *nspgrx, 
00705        char *spgrnx, char *pgnamx);
00706 
00716 int ccp4_lrsymm(const MTZ *mtz, int *nsymx, float rsymx[192][4][4]);
00717 
00727 int MtzParseLabin(char *labin_line, const char prog_labels[][31], 
00728            const int nlprgi, char user_labels[][2][31]);
00729 
00743 MTZCOL **ccp4_lrassn(const MTZ *mtz, const char labels[][31], const int nlabels, 
00744                 char types[][3]);
00745 
00759 int ccp4_lridx(const MTZ *mtz, const MTZSET *set, char crystal_name[64], 
00760             char dataset_name[64], char project_name[64], int *isets, 
00761             float datcell[6], float *datwave);
00762 
00778 int ccp4_lrrefl(const MTZ *mtz, float *resol, float adata[], int logmss[], int iref);
00779 
00796 int ccp4_lrreff(const MTZ *mtz, float *resol, float adata[], int logmss[],
00797                 const MTZCOL *lookup[], const int ncols, const int iref);
00798 
00806 int ccp4_ismnf(const MTZ *mtz, const float datum);
00807 
00813 int ccp4_lhprt(const MTZ *mtz, int iprint);
00814 
00821 int ccp4_lhprt_adv(const MTZ *mtz, int iprint);
00822 
00830 int ccp4_lrbat(MTZBAT *batch, float *buf, char *charbuf, int iprint);
00831 
00836 int MtzPrintBatchHeader(const MTZBAT *batch);
00837 
00845 int ccp4_lwtitl(MTZ *mtz, const char *ftitle, int flag);
00846 
00856 int MtzSetSortOrder(MTZ *mtz, MTZCOL *colsort[5]);
00857 
00864 int MtzAddHistory(MTZ *mtz, const char history[][MTZRECORDLENGTH], const int nlines);
00865 
00880 int ccp4_lwsymm(MTZ *mtz, int nsymx, int nsympx, float rsymx[192][4][4], 
00881                 char ltypex[], int nspgrx, char spgrnx[], char pgnamx[]);
00882 
00883 /* Assign columns for writing. Check to see if columns already exist,
00884  * else create them. New columns are assigned to the base dataset if it 
00885  * exists, else the first dataset.
00886  * @param mtz pointer to MTZ struct
00887  * @param labels Input array of column labels to be assigned.
00888  * @param nlabels Number of columns.
00889  * @param types Input array of column types of columns.
00890  * @param iappnd If iappnd = 0, then deactivate columns which are
00891  *   not selected (allows one to write out a subset of columns). Else
00892  *   if iappnd = 1, append these columns to existing ones.
00893  * @return Array of pointers to columns in MTZ struct.
00894  */
00895 MTZCOL **ccp4_lwassn(MTZ *mtz, const char labels[][31], const int nlabels, 
00896              const char types[][3], const int iappnd);
00897 
00898 /* Add or update a dataset in the MTZ structure. If the crystal name is
00899  * not recognised, then a new crystal is created containing a single
00900  * dataset. If the crystal name is recognised, then the parameters of
00901  * the crystal are updated. The child dataset is then created if necessary
00902  * or an existing dataset updated.
00903  * Note that this function is used to update crystal parameters, as well
00904  * as add crystals. If a duplicate crystal name is used by mistake, then 
00905  * the old crystal parameters are lost.
00906  * @param mtz pointer to MTZ struct
00907  * @param crystal_name Crystal name
00908  * @param dataset_name Dataset name
00909  * @param project_name Project name
00910  * @param datcell Cell dimensions of crystal that dataset belongs to.
00911  * @param datwave X-ray wavelength associated with dataset.
00912  * @return 1 on success, 0 on failure
00913  */
00914 int ccp4_lwidx(MTZ *mtz, const char crystal_name[],  const char dataset_name[],
00915         const char project_name[], const float datcell[6], const float *datwave);
00916 
00917 
00930 int ccp4_lwrefl(MTZ *mtz, const float adata[], MTZCOL *lookup[], 
00931                  const int ncol, const int iref);
00932 
00946 int ccp4_lwbat(MTZ *mtz, MTZBAT *batch, const int batno, const float *buf, const char *charbuf);
00947 
00948 int ccp4_lwbsetid(MTZ *mtz, MTZBAT *batch, const char xname[], const char dname[]);
00949 
00950 /* -- Below here there are no implementations -- */
00951 
00952 /* COMPLEX HLToSF(float hla, float hlb, float hlc, float hld, BOOLEAN centric); */
00953 /* Returns the mean structure factor as a complex number from a structure
00954    factor probability distribution described by Hendrickson/Lattman
00955    coefficients. If `centric == TRUE`, the coefficients describe a centric
00956    distribution. */
00957 
00958 /* MTZ *MtzSort(MTZ *mtz, char *ident); */
00959 /* Sorts `mtz` using the identifiers (separated by spaces) in `ident` as
00960    keys. Sorting can be done on up to 200 columns. A pointer to `*mtz` is
00961    returned. */
00962 
00963 /* MTZ *HLCombine (MTZ *to, float toscale, MTZ *frm, float frmscale); */
00964 /* Combines extra phase information for common reflections between 'frm'
00965    and 'to' into the phase information of 'to'. The phase probabilities
00966    are described by Hendrickson Lattman coefficients, with the identifiers
00967    "HLA", "HLB", HLC", and "HLD", the indices are identified by "H", "K" 
00968    and "L". HL-coeffs from 'to' are scaled by 'toscale', the coeffs from
00969    'frm' are scaled by 'frmscale'. A pointer to `to` is returned. */
00970 
00971 /* void MtzPhiFom(MTZ *mtz); */
00972 /* Calculates the best phase and the figure of from Hendrickson Lattman
00973    coefficients. The following columns should be present in `mtz`:
00974    "H", "K" & "L" (indices); "PHIB" & "FOM" (best phase (degrees) and figure of
00975    merit); "HLA", "HLB", "HLC" & "HLD" (Hendrickson Lattman coefficients). */
00976 
00977 /* MTZ *MtzCopy(MTZ *frm); */
00978 /* Produces an exact copy of `frm` and returns a pointer to it. */
00979 
00980 /* MTZ *MtzColAppend(MTZ *mtz, char *ident, char type); */
00981 /* Appends a column to `*mtz` with identity `ident` and type `type`, provided
00982    no column with identity `ident` exists. */
00983 
00984 /* MTZ *MtzColRemove(MTZ *mtz, char *ident); */
00985 /* Removes a column from `*mtz` with identity `ident`. */
00986 
00987 /* MTZ *MtzUpdateRanges(MTZ *mtz); */
00988 /* Updates ranges of all columns in `mtz` and returns `mtz`. */
00989 
00990 /* MTZCOL *MtzColNewRange(MTZCOL *col, int nref); */
00991 /* Updates the minimum & maximum values in `col` and returns `col`. */
00992 
00993 /* int *MtzUnique(MTZ *mtz, char *ident); */
00994 /* Returns an array (k) of indices: k[j] returns the first occurrence of a set
00995    of idents, eg. MtzUnique(mtz, "H K L") returns an array from which all the 
00996    unique reflections can be determined by indexing with k: k[i] is the index
00997    of the last relection of a set which all have the same hkl indices. It is
00998    assumed that `mtz` is sorted, using `ident` as keys. */
00999 
01000 /* float PhaseProb(float phase, float hla, float hlb, float hlc, float hld,
01001                 BOOLEAN centric); */
01002 /* Returns the probability of `phase` (expressed in radians) as determined by
01003    the Hendrickson-Lattmann coefficients `hla`, `hlb`, `hlc` and `hld`. If
01004    `centric == TRUE`, the coefficients describe a centric distribution. */
01005 
01006 #ifdef __cplusplus
01007 } }
01008 #endif
01009 #endif