00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef __MMDB_MMCIF__
00046 #define __MMDB_MMCIF__
00047
00048
00049 #include "mmdb_io_stream.h"
00050
00051 namespace mmdb {
00052
00053 namespace mmcif {
00054
00055
00056
00057
00058 enum MMCIF_ITEM {
00059 MMCIF_Category = 0,
00060 MMCIF_Struct = 1,
00061 MMCIF_Loop = 2,
00062 MMCIF_Data = 3
00063 };
00064
00065 DefineClass(Category);
00066 DefineStreamFunctions(Category);
00067
00071
00085 class Category : public io::Stream {
00086
00087 friend class Data;
00088
00089 public :
00090
00092 Category ();
00093
00096 Category ( cpstr N );
00097
00099 Category ( io::RPStream Object );
00100
00102 ~Category();
00103
00107 inline pstr GetCategoryName() { return name; }
00108
00111 void SetCategoryName ( cpstr N );
00112
00119 virtual MMCIF_ITEM GetCategoryID() { return MMCIF_Category; }
00120
00124 virtual void WriteMMCIF ( io::RFile ) {}
00125
00136 virtual void Optimize();
00137
00145 void Sort();
00146
00153 int GetTagNo ( cpstr ttag );
00154
00168 int AddTag ( cpstr ttag );
00169
00171 int GetNofTags() { return nTags; }
00172
00179 pstr GetTag ( int tagNo );
00180
00184 void PrintTags();
00185
00208 bool CheckTags ( cpstr * tagList );
00209
00217 virtual void Copy ( PCategory Category );
00218
00220 void write ( io::RFile f );
00221
00223 void read ( io::RFile f );
00224
00225 protected:
00226 int nTags;
00227 pstr name;
00228 psvector tag;
00229 ivector index;
00230 int nAllocTags;
00231
00232 void InitCategory ();
00233 virtual void FreeMemory ();
00234 void ExpandTags ( int nTagsNew );
00235 void PutCategoryName ( cpstr newName );
00236
00237 };
00238
00239
00240
00241
00242
00243 DefineClass(Struct);
00244 DefineStreamFunctions(Struct);
00245
00248 extern const int CIF_NODATA_DOT;
00249 extern const int CIF_NODATA_QUESTION;
00250 extern cpstr CIF_NODATA_DOT_FIELD;
00251 extern cpstr CIF_NODATA_QUESTION_FIELD;
00252
00255
00281 class Struct : public Category {
00282
00283 public :
00284
00286 Struct ();
00287
00290 Struct ( cpstr N );
00291
00293 Struct ( io::RPStream Object );
00294
00296 ~Struct();
00297
00307 void AddField ( cpstr F, cpstr T, bool Concatenate=false );
00308
00310 MMCIF_ITEM GetCategoryID() { return MMCIF_Struct; }
00311
00322 void Optimize();
00323
00338 pstr GetField ( int tagNo );
00339
00383 int GetString ( pstr & S, cpstr TName, bool Remove=false );
00384
00401 pstr GetString ( cpstr TName, int & RC );
00402
00403
00408 int DeleteField ( cpstr TName );
00409
00425 int GetReal ( realtype & R, cpstr TName, bool Remove=false );
00426
00443 int GetInteger ( int & I, cpstr TName, bool Remove=false );
00444
00456 void PutString ( cpstr S, cpstr TName,
00457 bool NonBlankOnly=false );
00458
00463 void PutDate ( cpstr T );
00464
00472 void PutNoData ( int NoDataType, cpstr T );
00473
00480 void PutReal ( realtype R, cpstr TName, int prec=8 );
00481
00487 void PutReal ( realtype R, cpstr TName, cpstr format );
00488
00493 void PutInteger ( int I, cpstr TName );
00494
00510 bool WriteMMCIFStruct ( cpstr FName,
00511 io::GZ_MODE gzipMode=io::GZM_CHECK );
00512
00518 void WriteMMCIF ( io::RFile f );
00519
00527 void Copy ( PCategory Struct );
00528
00530 void write ( io::RFile f );
00531
00533 void read ( io::RFile f );
00534
00535 protected:
00536 psvector field;
00537
00538 void InitStruct();
00539 void FreeMemory();
00540
00541 };
00542
00543
00544
00545
00546
00547 DefineClass(Loop);
00548 DefineStreamFunctions(Loop);
00549
00552
00640 class Loop : public Category {
00641
00642 friend class Data;
00643
00644 public :
00645
00647 Loop ();
00648
00651 Loop ( cpstr N );
00652
00654 Loop ( io::RPStream Object );
00655
00657 ~Loop();
00658
00664 void AddLoopTag ( cpstr T, bool Remove=true );
00665
00683 void AddString ( cpstr S, bool NonBlankOnly=false );
00684
00699 void AddNoData ( int NoDataType );
00700
00713 void AddReal ( realtype R, int prec=8 );
00714
00728 void AddReal ( realtype R, cpstr format );
00729
00741 void AddInteger ( int I );
00742
00746 int GetLoopLength() { return nRows; }
00747
00764 pstr GetField ( int rowNo, int tagNo );
00765
00812 int GetString ( pstr & S, cpstr TName, int nrow,
00813 bool Remove=false );
00814
00834 pstr GetString ( cpstr TName, int nrow, int & RC );
00835
00850 void CopyString ( pstr buf, int maxlength,
00851 cpstr TName, int nrow, int & RC );
00852
00859 int DeleteField ( cpstr TName, int nrow );
00860
00868 int DeleteRow ( int nrow );
00869
00887 int GetReal ( realtype & R, cpstr TName, int nrow,
00888 bool Remove=false );
00889
00902 void CopyReal ( realtype & R, cpstr TName, int nrow, int & RC );
00903
00916 void CopyInteger ( int & I, cpstr TName, int nrow, int & RC );
00917
00935 int GetInteger ( int & I, cpstr TName, int nrow,
00936 bool Remove=false );
00937
00992 int GetSVector ( psvector & S, cpstr TName,
00993 int i1=0, int i2=MaxInt4,
00994 bool Remove=false );
00995
01047 int GetRVector ( rvector & R, cpstr TName,
01048 int i1=0, int i2=MaxInt4,
01049 bool Remove=false );
01050
01075 int GetIVector ( ivector & I, cpstr TName,
01076 int i1=0, int i2=MaxInt4,
01077 bool Remove=false );
01078
01092 void PutString ( cpstr S, cpstr T, int nrow );
01093
01107 void PutNoData ( int NoDataType, cpstr T, int nrow );
01108
01121 void PutReal ( realtype R, cpstr T, int nrow, int prec=8 );
01122
01134 void PutReal ( realtype R, cpstr T, int nrow, cpstr format );
01135
01146 void PutInteger ( int I, cpstr T, int nrow );
01147
01180 void PutSVector ( psvector S, cpstr T, int i1, int i2 );
01181
01197 void PutRVector ( rvector R, cpstr T, int i1, int i2,
01198 int prec=8 );
01199
01213 void PutIVector ( ivector I, cpstr T, int i1, int i2 );
01214
01216 MMCIF_ITEM GetCategoryID() { return MMCIF_Loop; }
01217
01228 void Optimize();
01229
01245 bool WriteMMCIFLoop ( cpstr FName,
01246 io::GZ_MODE gzipMode=io::GZM_CHECK );
01247
01253 void WriteMMCIF ( io::RFile f );
01254
01262 void Copy ( PCategory Loop );
01263
01265 void write ( io::RFile f );
01266
01268 void read ( io::RFile f );
01269
01270 protected:
01271 int nRows;
01272 psmatrix field;
01273 int iColumn,nAllocRows;
01274
01275 void InitLoop ();
01276 void FreeMemory ();
01277 void DeleteFields ();
01278 void ExpandRows ( int nRowsNew );
01279
01280 };
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290 enum CIF_WARNING {
01291 CIFW_UnrecognizedItems = 0x00000020,
01292 CIFW_MissingField = 0x00000040,
01293 CIFW_EmptyLoop = 0x00000080,
01294 CIFW_UnexpectedEOF = 0x00000100,
01295 CIFW_LoopFieldMissing = 0x00000200,
01296 CIFW_NotAStructure = 0x00000400,
01297 CIFW_NotALoop = 0x00000800,
01298 CIFW_DuplicateTag = 0x00001000
01299 };
01300
01301
01302
01303
01304 enum CIF_RC {
01305 CIFRC_Loop = 2,
01306 CIFRC_Structure = 1,
01307 CIFRC_Ok = 0,
01308 CIFRC_StructureNoTag = -1,
01309 CIFRC_LoopNoTag = -2,
01310 CIFRC_NoCategory = -3,
01311 CIFRC_WrongFormat = -4,
01312 CIFRC_NoTag = -5,
01313 CIFRC_NotAStructure = -6,
01314 CIFRC_NotALoop = -7,
01315 CIFRC_WrongIndex = -8,
01316 CIFRC_NoField = -9,
01317 CIFRC_Created = -12,
01318 CIFRC_CantOpenFile = -13,
01319 CIFRC_NoDataLine = -14,
01320 CIFRC_NoData = -15
01321 };
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355 enum CIF_FLAG {
01356 CIFFL_PrintWarnings = 0x00000001,
01357 CIFFL_StopOnWarnings = 0x00000002,
01358 CIFFL_SuggestCategories = 0x00000004,
01359 CIFFL_SuggestTags = 0x00000008
01360 };
01361
01362 DefineClass(Data);
01363 DefineStreamFunctions(Data);
01364
01365
01368
01471 class Data : public io::Stream {
01472
01473 friend class File;
01474
01475 public :
01476
01478 Data ();
01479
01482 Data ( cpstr N );
01483
01485 Data ( io::RPStream Object );
01486
01488 ~Data();
01489
01490
01491
01492
01498 void SetPrintWarnings ( bool SPW );
01499
01504 void SetStopOnWarning ( bool SOW );
01505
01537 void SetFlag ( CIF_FLAG F );
01538
01553 void RemoveFlag ( CIF_FLAG F );
01554
01572 inline int GetWarnings() { return Warning; }
01573
01591
01603 void SetWrongFields ( cpstr *cats, cpstr *tags );
01604
01621
01637 int ReadMMCIFData ( cpstr FName,
01638 io::GZ_MODE gzipMode=io::GZM_CHECK );
01639
01661
01706 int ReadMMCIFData ( io::RFile f, pstr S, int & lcount );
01707
01718 bool WriteMMCIFData ( cpstr FName,
01719 io::GZ_MODE gzipMode=io::GZM_CHECK );
01720
01731
01761 void WriteMMCIF ( io::RFile f );
01762
01763
01764
01765
01768 inline int GetNumberOfCategories () { return nCategories; }
01769
01782 PCategory GetCategory ( int categoryNo );
01783
01792 PStruct GetStructure ( cpstr CName );
01793
01802 PLoop GetLoop ( cpstr CName );
01803
01817 PLoop FindLoop ( cpstr * tagList );
01818
01827 void GetDataName ( pstr & dname, bool Remove=false );
01828
01830 inline pstr GetDataName() { return name; }
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847 int CheckData ( cpstr CName, cpstr TName );
01848
01849 int DeleteCategory ( cpstr CName );
01850 int DeleteStructure ( cpstr CName );
01851 int DeleteLoop ( cpstr CName );
01852
01853
01854
01855
01856 void Optimize();
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873 int GetString ( pstr & Dest, cpstr CName, cpstr TName,
01874 bool Remove=false );
01875 pstr GetString ( cpstr CName, cpstr TName, int & RC );
01876 int DeleteField ( cpstr CName, cpstr TName );
01877 int GetReal ( realtype & R, cpstr CName,
01878 cpstr TName, bool Remove=false );
01879 int GetInteger ( int & I, cpstr CName, cpstr TName,
01880 bool Remove=false );
01881
01882
01883
01884
01885
01886 int GetLoopLength ( cpstr CName );
01887
01888
01889
01890
01891
01892
01893
01894
01895 int GetLoopString ( pstr & Dest, cpstr CName,
01896 cpstr TName, int nrow,
01897 bool Remove=false );
01898 pstr GetLoopString ( cpstr CName, cpstr TName,
01899 int nrow, int & RC );
01900 int DeleteLoopField ( cpstr CName, cpstr TName,
01901 int nrow );
01902 int GetLoopReal ( realtype & R, cpstr CName,
01903 cpstr TName, int nrow,
01904 bool Remove=false );
01905 int GetLoopInteger ( int & I, cpstr CName,
01906 cpstr TName, int nrow,
01907 bool Remove=false );
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920 int GetLoopSVector ( psvector & S, cpstr CName,
01921 cpstr TName, int i1=0, int i2=MaxInt4,
01922 bool Remove=false );
01923 int GetLoopRVector ( rvector & R, cpstr CName,
01924 cpstr TName, int i1=0, int i2=MaxInt4,
01925 bool Remove=false );
01926 int GetLoopIVector ( ivector & I, cpstr CName,
01927 cpstr TName, int i1=0, int i2=MaxInt4,
01928 bool Remove=false );
01929
01930
01931
01932
01933
01934
01935
01936 void FreeMemory ( int key );
01937
01938 void PutDataName ( cpstr dname );
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951 int PutNoData ( int NoDataType, cpstr CName,
01952 cpstr TName );
01953 int PutString ( cpstr S, cpstr CName,
01954 cpstr TName, bool Concatenate=false );
01955 int PutDate ( cpstr CName, cpstr TName );
01956 int PutReal ( realtype R, cpstr CName, cpstr TName,
01957 int prec=8 );
01958 int PutInteger ( int I, cpstr CName, cpstr TName );
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983 int AddLoop ( cpstr CName, PLoop & cifLoop );
01984 int AddStructure ( cpstr CName, PStruct & cifStruct );
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995 int PutLoopNoData ( int NoDataType, cpstr CName,
01996 cpstr TName, int nrow );
01997 int PutLoopString ( cpstr S, cpstr CName,
01998 cpstr TName, int nrow );
01999 int PutLoopReal ( realtype R, cpstr CName,
02000 cpstr TName, int nrow,
02001 int prec=8 );
02002 int PutLoopInteger ( int I, cpstr CName, cpstr TName,
02003 int nrow );
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015 int PutLoopSVector ( psvector S, cpstr CName,
02016 cpstr TName, int i1, int i2 );
02017 int PutLoopRVector ( rvector R, cpstr CName,
02018 cpstr TName, int i1, int i2,
02019 int prec=8 );
02020 int PutLoopIVector ( ivector I, cpstr CName,
02021 cpstr TName, int i1, int i2 );
02022
02023 int RenameCategory ( cpstr CName, cpstr newCName );
02024
02025
02026
02027 void Copy ( PData Data );
02028 int CopyCategory ( PData Data, cpstr CName,
02029 cpstr newCName=NULL );
02030
02031 void PrintCategories();
02032
02033 void write ( io::RFile f );
02034 void read ( io::RFile f );
02035
02036 protected:
02037 pstr name;
02038 int nCategories;
02039 PPCategory Category;
02040 ivector index;
02041 int flags;
02042 int Warning;
02043 int loopNo;
02044 int tagNo;
02045 psvector WrongCat;
02046 psvector WrongTag;
02047 int nWrongFields;
02048
02049 void InitData ();
02050 void FreeWrongFields ();
02051 bool CheckWrongField ( cpstr C, cpstr T );
02052 void Sort ();
02053
02054
02055
02056
02057
02058
02059 int GetCategoryNo ( cpstr cname );
02060 int AddCategory ( cpstr cname );
02061 int DeleteCategory ( int CatNo );
02062
02063 void GetDataItem ( io::RFile f, pstr S, pstr & L, pstr & p,
02064 int & lcount, int & llen );
02065 void GetLoop ( io::RFile f, pstr S, pstr & L, pstr & p,
02066 int & lcount, int & llen );
02067 int GetField ( io::RFile f, pstr S, pstr & L, pstr & p,
02068 int & lcount, int & llen );
02069
02070 };
02071
02072
02073
02074
02075
02076 DefineClass(File);
02077 DefineStreamFunctions(File);
02078
02079 class File : public io::Stream {
02080
02081 public :
02082 int nData;
02083 ivector index;
02084 PPData data;
02085
02086 File ();
02087 File ( cpstr FName, io::GZ_MODE gzipMode=io::GZM_CHECK );
02088 File ( io::RPStream Object );
02089 ~File();
02090
02091 void SetPrintWarnings ( bool SPW ) { PrintWarnings = SPW; }
02092 void SetStopOnWarning ( bool SOW ) { StopOnWarning = SOW; }
02093
02094 int ReadMMCIFFile ( cpstr FName,
02095 io::GZ_MODE gzipMode=io::GZM_CHECK );
02096 int WriteMMCIFFile ( cpstr FName,
02097 io::GZ_MODE gzipMode=io::GZM_CHECK );
02098
02099 int GetNofData() { return nData; }
02100 PData GetCIFData ( int dataNo );
02101 PData GetCIFData ( cpstr DName );
02102 int AddCIFData ( cpstr DName );
02103 int DeleteCIFData ( cpstr DName );
02104 int DeleteCIFData ( int dataNo );
02105 int GetCIFDataNo ( cpstr DName );
02106
02107 void WriteMMCIF ( io::RFile f );
02108
02109 void Copy ( PFile File );
02110
02111 void write ( io::RFile f );
02112 void read ( io::RFile f );
02113
02114 protected:
02115 int nAllocData;
02116 bool PrintWarnings;
02117 bool StopOnWarning;
02118
02119 void InitFile ();
02120 void FreeMemory ();
02121 void Sort ();
02122 void ExpandData ( int nDataNew );
02123
02124 };
02125
02126
02127 extern pstr GetMMCIFInputBuffer ( int & LineNo );
02128
02129
02130
02131
02132
02133 extern int isCIF ( cpstr FName, io::GZ_MODE gzipMode=io::GZM_CHECK );
02134 extern int isCIF ( io::RFile f );
02135
02136 pstr GetCIFMessage ( pstr M, int RC );
02137
02138
02139 }
02140
02141 }
02142
02143
02144 #endif
02145
02146