mmcif::Data represents mmCIF's "data" category, which keeps structures and loops and is mandatory element of mmCIF file. More...
#include <mmdb_mmcif_.h>

Public Member Functions | |
| Data () | |
| Basic constructor. | |
| Data (cpstr N) | |
| Constructor that assigns data block name. | |
| Data (io::RPStream Object) | |
| Constructor for MMDB data streaming functions. | |
| ~Data () | |
| Destructor. | |
| void | SetPrintWarnings (bool SPW) |
| Sets flag to print warnings on reading mmCIF files. | |
| void | SetStopOnWarning (bool SOW) |
| Sets flag to stop on warning when reading an mmCIF file. | |
| void | SetFlag (CIF_FLAG F) |
| Sets optional flag(s) for reading mmCIF files. By default, no flags are set. | |
| void | RemoveFlag (CIF_FLAG F) |
| Removes optional flag(s) for reading mmCIF files. By default, no flags are set. | |
| int | GetWarnings () |
| Returns bit-encoded warnings issued at last file read. | |
| void | SetWrongFields (cpstr *cats, cpstr *tags) |
| Sets category names and tags that are to be ignored on file read. | |
| int | ReadMMCIFData (cpstr FName, io::GZ_MODE gzipMode=io::GZM_CHECK) |
| Reads mmCIF data block from file. | |
| int | ReadMMCIFData (io::RFile f, pstr S, int &lcount) |
| Reads sequential mmCIF data blocks from file. | |
| bool | WriteMMCIFData (cpstr FName, io::GZ_MODE gzipMode=io::GZM_CHECK) |
| Writes mmCIF data block into file. | |
| void | WriteMMCIF (io::RFile f) |
| Writes (next) mmCIF data block into file. | |
| int | GetNumberOfCategories () |
| Returns the number of categories (structures and loops) in data block. | |
| PCategory | GetCategory (int categoryNo) |
| Retrieves pointer to category (a structure or a loop) by category number. | |
| PStruct | GetStructure (cpstr CName) |
| Retrieves mmCIF structure with given name. | |
| PLoop | GetLoop (cpstr CName) |
| Retrieves mmCIF loop with given name. | |
| PLoop | FindLoop (cpstr *tagList) |
| Finds loop containing all tags from the tag list provided. | |
| void | GetDataName (pstr &dname, bool Remove=false) |
| Retrieves data block name into dynamically-allocated string. | |
| pstr | GetDataName () |
| Returns data block name. | |
| int | CheckData (cpstr CName, cpstr TName) |
| int | DeleteCategory (cpstr CName) |
| int | DeleteStructure (cpstr CName) |
| int | DeleteLoop (cpstr CName) |
| void | Optimize () |
| int | GetString (pstr &Dest, cpstr CName, cpstr TName, bool Remove=false) |
| pstr | GetString (cpstr CName, cpstr TName, int &RC) |
| int | DeleteField (cpstr CName, cpstr TName) |
| int | GetReal (realtype &R, cpstr CName, cpstr TName, bool Remove=false) |
| int | GetInteger (int &I, cpstr CName, cpstr TName, bool Remove=false) |
| int | GetLoopLength (cpstr CName) |
| int | GetLoopString (pstr &Dest, cpstr CName, cpstr TName, int nrow, bool Remove=false) |
| pstr | GetLoopString (cpstr CName, cpstr TName, int nrow, int &RC) |
| int | DeleteLoopField (cpstr CName, cpstr TName, int nrow) |
| int | GetLoopReal (realtype &R, cpstr CName, cpstr TName, int nrow, bool Remove=false) |
| int | GetLoopInteger (int &I, cpstr CName, cpstr TName, int nrow, bool Remove=false) |
| int | GetLoopSVector (psvector &S, cpstr CName, cpstr TName, int i1=0, int i2=MaxInt4, bool Remove=false) |
| int | GetLoopRVector (rvector &R, cpstr CName, cpstr TName, int i1=0, int i2=MaxInt4, bool Remove=false) |
| int | GetLoopIVector (ivector &I, cpstr CName, cpstr TName, int i1=0, int i2=MaxInt4, bool Remove=false) |
| void | FreeMemory (int key) |
| void | PutDataName (cpstr dname) |
| int | PutNoData (int NoDataType, cpstr CName, cpstr TName) |
| int | PutString (cpstr S, cpstr CName, cpstr TName, bool Concatenate=false) |
| int | PutDate (cpstr CName, cpstr TName) |
| int | PutReal (realtype R, cpstr CName, cpstr TName, int prec=8) |
| int | PutInteger (int I, cpstr CName, cpstr TName) |
| int | AddLoop (cpstr CName, PLoop &cifLoop) |
| int | AddStructure (cpstr CName, PStruct &cifStruct) |
| int | PutLoopNoData (int NoDataType, cpstr CName, cpstr TName, int nrow) |
| int | PutLoopString (cpstr S, cpstr CName, cpstr TName, int nrow) |
| int | PutLoopReal (realtype R, cpstr CName, cpstr TName, int nrow, int prec=8) |
| int | PutLoopInteger (int I, cpstr CName, cpstr TName, int nrow) |
| int | PutLoopSVector (psvector S, cpstr CName, cpstr TName, int i1, int i2) |
| int | PutLoopRVector (rvector R, cpstr CName, cpstr TName, int i1, int i2, int prec=8) |
| int | PutLoopIVector (ivector I, cpstr CName, cpstr TName, int i1, int i2) |
| int | RenameCategory (cpstr CName, cpstr newCName) |
| void | Copy (PData Data) |
| int | CopyCategory (PData Data, cpstr CName, cpstr newCName=NULL) |
| void | PrintCategories () |
| void | write (io::RFile f) |
| void | read (io::RFile f) |
Protected Member Functions | |
| void | InitData () |
| void | FreeWrongFields () |
| bool | CheckWrongField (cpstr C, cpstr T) |
| void | Sort () |
| int | GetCategoryNo (cpstr cname) |
| int | AddCategory (cpstr cname) |
| int | DeleteCategory (int CatNo) |
| void | GetDataItem (io::RFile f, pstr S, pstr &L, pstr &p, int &lcount, int &llen) |
| void | GetLoop (io::RFile f, pstr S, pstr &L, pstr &p, int &lcount, int &llen) |
| int | GetField (io::RFile f, pstr S, pstr &L, pstr &p, int &lcount, int &llen) |
Protected Attributes | |
| pstr | name |
| int | nCategories |
| PPCategory | Category |
| ivector | index |
| int | flags |
| int | Warning |
| int | loopNo |
| int | tagNo |
| psvector | WrongCat |
| psvector | WrongTag |
| int | nWrongFields |
Friends | |
| class | File |
mmcif::Data represents mmCIF's "data" category, which keeps structures and loops and is mandatory element of mmCIF file.
mmCIF's "data" category has the following form:
data_DataName
_structure1.tag1 value1
..........
loop_
..........
In the above example, all structures and loops that follow data_ keyword until next data_ or end of file are part of data category with name DataName.
mmcif::Data represents this construct by keeping a list of mmcif::Struct and mmcif::Loop class instances associated with the corresponding categories in the data block.
The data object is created automatically when an mmCIF file is read, or it may be created programatically and then pushed into file.
Access to data is provided via category (structures and loops) names, tags and data indexes (in case of loops). Alternatively, pointers to contained structures and loops may be obtained first, an used for fetching data using mmcif::Struct's and mmcif::Loop's interface functions.
The following code gives an example of creating mmCIF's data category and populating it:
mmcif::Data data;
// Specify data name:
data.PutDataName ( "Sample_Data" );
// the following statement:
data.PutInteger ( 12345,"_category1","id" );
// creates structure "_category1" with tag "id" and assigns it
// the integer value of 12345.
data.PutString ( "a name","_category1","name" );
// Loops may be created quite similarly:
data.PutLoopInteger ( 12345 ,"_loop1","id" ,2 );
data.PutLoopInteger ( "a name","_loop1","name",0 );
// push data into a file
data.WriteMMCIFData ( "sample.cif" );
The resulting file sample.cif will contain:
data_Sample_Data
_category1.id 12345
_category1.name "a name"
loop_
_loop1.id
_loop1.name
. "a name"
. .
12345 .
The same result may be achieved differently:
mmcif::Data data;
mmcif::PStruct mmCIFStruct; // equivalent to mmcif::Struct *mmCIFStruct
mmcif::PLoop mmCIFLoop; // equivalent to mmcif::Loop *mmCIFLoop
// Specify data name:
data.PutDataName ( "Sample_Data" );
// create new mmCIF's structure in the data block:
data.AddStructure ( "_category1",mmCIFStruct );
if (mmCIFStruct) {
mmCIFStruct->PutInteger ( 12345 ,"id" );
mmCIFStruct->PutString ( "a name","name" );
}
// similarly for the loop:
data.AddLoop ( "_loop1",mmCIFLoop );
if (mmCIFLoop) {
mmCIFLoop->PutInteger ( 12345 ,"id" ,2 );
mmCIFLoop->PutString ( "a name","name",0 );
}
// push data into a file
data.WriteMMCIFData ( "sample.cif" );
See general principles of working with mmCIF files and mmCIF hierarchies, as well as some code samples, in Section "mmcif_handler".
| mmdb::mmcif::Data::Data | ( | ) |
Basic constructor.
| mmdb::mmcif::Data::Data | ( | cpstr | N ) |
Constructor that assigns data block name.
| [in] | N | data block name. |
| mmdb::mmcif::Data::Data | ( | io::RPStream | Object ) |
Constructor for MMDB data streaming functions.
| mmdb::mmcif::Data::~Data | ( | ) |
Destructor.
| int mmdb::mmcif::Data::AddCategory | ( | cpstr | cname ) | [protected] |
| int mmdb::mmcif::Data::AddLoop | ( | cpstr | CName, |
| PLoop & | cifLoop | ||
| ) |
| int mmdb::mmcif::Data::AddStructure | ( | cpstr | CName, |
| PStruct & | cifStruct | ||
| ) |
| void mmdb::mmcif::Data::Copy | ( | PData | Data ) |
| int mmdb::mmcif::Data::DeleteCategory | ( | int | CatNo ) | [protected] |
| int mmdb::mmcif::Data::DeleteCategory | ( | cpstr | CName ) |
| int mmdb::mmcif::Data::DeleteLoop | ( | cpstr | CName ) |
| int mmdb::mmcif::Data::DeleteStructure | ( | cpstr | CName ) |
| PLoop mmdb::mmcif::Data::FindLoop | ( | cpstr * | tagList ) |
Finds loop containing all tags from the tag list provided.
| tagList | list of tags to be looked for. The list should be terminated by empty string "". The order of tags is not significant. |
The function will look for first loop that includes all tags from the list. The list does not have to include all tags for that loop in order for function to succeed. This function is useful for reading "dirty cifs" that may contain loops without a name.
| void mmdb::mmcif::Data::FreeMemory | ( | int | key ) |
| void mmdb::mmcif::Data::FreeWrongFields | ( | ) | [protected] |
| PCategory mmdb::mmcif::Data::GetCategory | ( | int | categoryNo ) |
Retrieves pointer to category (a structure or a loop) by category number.
| categoryNo | category number to retrieve. Categories are numbered from 0 to GetNumberOfCategories()-1. |
| int mmdb::mmcif::Data::GetCategoryNo | ( | cpstr | cname ) | [protected] |
| void mmdb::mmcif::Data::GetDataItem | ( | io::RFile | f, |
| pstr | S, | ||
| pstr & | L, | ||
| pstr & | p, | ||
| int & | lcount, | ||
| int & | llen | ||
| ) | [protected] |
| void mmdb::mmcif::Data::GetDataName | ( | pstr & | dname, |
| bool | Remove = false |
||
| ) |
Retrieves data block name into dynamically-allocated string.
| dname | pointer reference to a string that accepts data block name. If dname is not NULL, it is treated as a pre-allocated string, which is disposed before copying. The application is responsible for deallocating dname. |
| Remove | flag to remove name from the data block. |
| pstr mmdb::mmcif::Data::GetDataName | ( | ) | [inline] |
Returns data block name.
| int mmdb::mmcif::Data::GetField | ( | io::RFile | f, |
| pstr | S, | ||
| pstr & | L, | ||
| pstr & | p, | ||
| int & | lcount, | ||
| int & | llen | ||
| ) | [protected] |
| void mmdb::mmcif::Data::GetLoop | ( | io::RFile | f, |
| pstr | S, | ||
| pstr & | L, | ||
| pstr & | p, | ||
| int & | lcount, | ||
| int & | llen | ||
| ) | [protected] |
| PLoop mmdb::mmcif::Data::GetLoop | ( | cpstr | CName ) |
Retrieves mmCIF loop with given name.
| CName | character string with name of the loop (must start with underscore). |
| int mmdb::mmcif::Data::GetLoopInteger | ( | int & | I, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | nrow, | ||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetLoopIVector | ( | ivector & | I, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | i1 = 0, |
||
| int | i2 = MaxInt4, |
||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetLoopLength | ( | cpstr | CName ) |
| int mmdb::mmcif::Data::GetLoopReal | ( | realtype & | R, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | nrow, | ||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetLoopRVector | ( | rvector & | R, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | i1 = 0, |
||
| int | i2 = MaxInt4, |
||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetLoopString | ( | pstr & | Dest, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | nrow, | ||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetLoopSVector | ( | psvector & | S, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | i1 = 0, |
||
| int | i2 = MaxInt4, |
||
| bool | Remove = false |
||
| ) |
| int mmdb::mmcif::Data::GetNumberOfCategories | ( | ) | [inline] |
Returns the number of categories (structures and loops) in data block.
| PStruct mmdb::mmcif::Data::GetStructure | ( | cpstr | CName ) |
Retrieves mmCIF structure with given name.
| CName | character string with name of the structure (must start with underscore). |
| int mmdb::mmcif::Data::GetWarnings | ( | ) | [inline] |
Returns bit-encoded warnings issued at last file read.
| void mmdb::mmcif::Data::InitData | ( | ) | [protected] |
| void mmdb::mmcif::Data::Optimize | ( | ) |
| void mmdb::mmcif::Data::PrintCategories | ( | ) |
| void mmdb::mmcif::Data::PutDataName | ( | cpstr | dname ) |
| int mmdb::mmcif::Data::PutLoopRVector | ( | rvector | R, |
| cpstr | CName, | ||
| cpstr | TName, | ||
| int | i1, | ||
| int | i2, | ||
| int | prec = 8 |
||
| ) |
| void mmdb::mmcif::Data::read | ( | io::RFile | f ) |
| int mmdb::mmcif::Data::ReadMMCIFData | ( | cpstr | FName, |
| io::GZ_MODE | gzipMode = io::GZM_CHECK |
||
| ) |
Reads mmCIF data block from file.
| FName | character null-terminated string with file name |
| gzipMode | flag to read compressed files:
|
This function will read 1st data block from the specified file. In case of non-zero return, use GetCIFMessage() function to print the corresponding error message or warning:
mmcif::Data data;
char errLog[500];
int rc;
rc = data.ReadMMCIFData ( "myfile.cif" );
if (rc<0)
printf ( " There was an error:\n %s\n",
GetCIFMessage(errLog,rc) );
else if (rc>0)
printf ( " There were warnings:\n %s\n",
GetCIFMessage(errLog,rc) );
else
printf ( " mmCIF file has be read in successfully.\n" );
| int mmdb::mmcif::Data::ReadMMCIFData | ( | io::RFile | f, |
| pstr | S, | ||
| int & | lcount | ||
| ) |
Reads sequential mmCIF data blocks from file.
| RCFile | reference to a CFile object opened on a file |
| S | buffer string which represent a sliding read window. The string should be at least 500 characters long, initialized with empty-string value before first read, and passed unchanged between the reads |
| lcount | line counter, should be set zero before first read and passed unchanged between the reads. |
This function will read 1st data block from the current position of the file. The function is useful if a file contains more than a single data block, which should be read sequentially.
In case of non-zero return, use GetCIFMessage() function to print the corresponding error message or warning:
mmcif::Data mmCIFData; CFile f; char S[1000]; int rc,lcount; // open file first f.assign ( "/path/example.cif" ); if (!f.reset(true)) { printf ( " *** cannot open file '%s' for reading.\n", f.FileName() ); return -1; } lcount = 0; // global line counter through the file S[0] = char(0); // buffer string while (!f.FileEnd()) { rc = mmCIFData.ReadMMCIFData ( f,S,lcount ); if (rc!=CIFRC_Ok) { // error or warning if ((rc<0) && (!f.FileEnd())) { // error printf ( " *** error reading file %s:\n" " %s\n",f.FileName(),GetCIFMessage(S,rc) ); return rc; } else if (rc>0) { // warning printf ( " ... warning on reading file %s:\n" " %s\n",f.FileName(),GetCIFMessage(S,rc) ); } } else { // fetch needful values from the data block // ........ } } f.shut(); // close file // NOTE: do not delete mmcif::Struct/mmcif::Loop // classes obtained from mmcif::Data. If you do, get a crash. // All these structures are containers that dispose their // content automatically.
| void mmdb::mmcif::Data::RemoveFlag | ( | CIF_FLAG | F ) |
Removes optional flag(s) for reading mmCIF files. By default, no flags are set.
| [in] | F | flag or logical "or" of several flags to be removed (unset):
See more detail flag description in mmcif::Data::SetFlag(). |
| void mmdb::mmcif::Data::SetFlag | ( | CIF_FLAG | F ) |
Sets optional flag(s) for reading mmCIF files. By default, no flags are set.
| [in] | F | flag or logical "or" of several flags to be set:
|
| void mmdb::mmcif::Data::SetPrintWarnings | ( | bool | SPW ) |
Sets flag to print warnings on reading mmCIF files.
| [in] | SPW | flag to print warnings:
|
| void mmdb::mmcif::Data::SetStopOnWarning | ( | bool | SOW ) |
Sets flag to stop on warning when reading an mmCIF file.
| [in] | SOW | flag to stop on warning:
|
Sets category names and tags that are to be ignored on file read.
| [in] | cats | list of categories, terminated by NULL |
| [in] | tags | list of tags, terminated by NULL. |
This special function is to aid reading corrupt mmCIF files. The input lists should be of equal length 'n', and specify 'n' "wrong fields" that should be ignored on input. E.g., ith "wrong field" is identified as "cats[i].taga[i]". If "wrong field" belongs to a loop, then all the corresponding column is assumed to be absent. This corrects for mmCIF errors when defined tags in loops or structures do not have actual data associated with them.
In order to remove settings, call SetWrongFields(NULL,NULL).
Example:
| void mmdb::mmcif::Data::Sort | ( | ) | [protected] |
| void mmdb::mmcif::Data::write | ( | io::RFile | f ) |
| void mmdb::mmcif::Data::WriteMMCIF | ( | io::RFile | f ) |
Writes (next) mmCIF data block into file.
| RCFile | reference to a CFile object opened on a file. |
This function allows for sequential write of mmCIF data blocks into a file.
Example:
io::File f; mmcif::Data cifData; // open file first f.assign ( "/path/example.cif" ); if (!f.rewrite()) { printf ( " *** cannot open file '%s' for writing.\n", f.FileName() ); return -1; } cifData.PutDataName ( "name1" ); // fill cifData with all data needed cifData.WriteMMCIF ( f ); // first data block written cifData.FreeMemory ( 0 ); // reset data block to empty cifData.PutDataName ( "name2" ); // fill cifData with all data needed cifData.WriteMMCIF ( f ); // second data block written // add as many data blocks as needed // now close the file f.shut();
| bool mmdb::mmcif::Data::WriteMMCIFData | ( | cpstr | FName, |
| io::GZ_MODE | gzipMode = io::GZM_CHECK |
||
| ) |
Writes mmCIF data block into file.
| FName | character null-terminated string with file name |
| gzipMode | flag to read compressed files:
|
friend class File [friend] |
PPCategory mmdb::mmcif::Data::Category [protected] |
int mmdb::mmcif::Data::flags [protected] |
ivector mmdb::mmcif::Data::index [protected] |
int mmdb::mmcif::Data::loopNo [protected] |
pstr mmdb::mmcif::Data::name [protected] |
int mmdb::mmcif::Data::nCategories [protected] |
int mmdb::mmcif::Data::nWrongFields [protected] |
int mmdb::mmcif::Data::tagNo [protected] |
int mmdb::mmcif::Data::Warning [protected] |
psvector mmdb::mmcif::Data::WrongCat [protected] |
psvector mmdb::mmcif::Data::WrongTag [protected] |
1.7.2