ChemObj

TCHNExp

Constructor      TCHNExp(TAtomsInfo *AI)
Function returns arguments  
CalcSummFormula TEStringList* TEStringList *Exp = NULL The function is mostly for internal use, however:
If the Exp parameter is not NULL, the its strings will be the element symbols and objects (double*) - the amount of the element. The Exp->Objects have to be deleted afterwards. Returned value is NULL in this case. If the Exp is NULL then the function returns a pointer to a newly created TEstringObject. Do not forget to delete (double*) objects of the list!
CHN bool double &C
double &H
double &N
double &Mr
Returns true if everything is alright, and false otherwise. To get the percentage of carbon divide C by Mr. The same procedure for H and N.
CHN(double *Bf); bool   Analogues for the function above. Takes an array of four elements to put C, H, Nand Mr int it.
Composition TEString   Returns the composition of a given compound.
GetMult double   For internal use
LoadFromExpression bool const TEString &E
TEString &Msg
Initialises the object form a string like (C2H4). If an error is occurred during the process, the function returns false and fills the Msg with the explanation.
MolWeight double TEString &Msg Returns the molecular weight of a compound. If an error occured during the process (unknown element or whatsoever) the Msg string will contain the explanation. The function is the best way to check if the entered expression is  legal. If you use the function for this purpose, do not forget to empty Msg before!
SetMult void const TEString &S For internal use
SummFormula TEString const TEString &Separator Returns a summarised formula for a compound. Distinct elements will be separated by the Separator


 

TIDistribution

Constructor     TIDistribution()
Function returns arguments  
AddIsotope void TEList *Isotopes, int count Adds a new polynomial member to object. If you use not elemental isotopes but something different, you have to use TIsotope structure anyway.
Calc void TEList *S Calculates all possible variations polynomial members and puts the result into the S list
static CombineSerie void TEList *S, double threshold Combines values within a series (I meant single), which do not differ to more then the threshold
static DeleteSerie void TEList *S Deletes a series, deleting TSPoint pointers of the list
GetThreshold double   Returns current threshold (default value is 0.00001, which is 0.01%). The polynomial members with the value less than the threshold will be removed from a polynomial to improve the performance.
SetThreshold void double v Sets current threshold, see above
SetMaxPoints void int v The last restriction on the number of calculated point. The default value is 25000.

 

TIPattern, a wrapper for TIDistribution, calculating isotope patterns

Constructor     TIPattern(class TAtomsInfo *AI)
Function returns arguments  
Calc bool TEString Exp
TEString &Msg
bool Combine
double Delta
Calculates isotope distribution for the Exp. If there is an error occurred while translating the formula, the Msg parameter will be initialised with the errors and the function will return false. Use Combine to specify if the series points have to be combined if differ less that Delta. The function fills the Points with TSPoints.
Properties      
TEList * Points     Use this list to access its TSPoint values. The values are sorted in a descending way.



struct TIsotope
{
double Mr, W, Tag;
};


class TBasicAtomInfo
{
TEString Symbol,    // atom symbol, e.g. Mn
Name;                    // atom name e.g. manganeese
double Mr,             // molecular weight
Rad,                       // radius for bonds determination (Van der Waals)
Rad1,
Rad2;
short Number;         // atomic number
int DefColor;           // default colour
short Index;             // index of the record in the list; for internal use
double Tag;             // an additional value for internal use
TEList * Isotopes;  // the list of isotopes for an element
}

TAtomsInfo

Constructor     TAtomsInfo(TEString File, bool Text). Loads data to a file. The Text parameters specifies if the data should be read in a text or binary format. The file supplied with the library is a text file, it has t be read in a text format and better left unchanged.
Function returns arguments  
Count() int   Returns the number of elements in the list
GetAtomInfo TBasicAtomInfo* short index Returns a pointer to an element information
GetAtomInfo TBasicAtomInfo* const TEString &Symbol Returns a pointer to an element information and NULL otherwise
IsAtom bool char *p Checks if two characters long value is an element name. It starts from the elements which symbols have two letters and ends up on the one-lettered elements.
IsElement bool TEString S A "stupid" version of IsAtom. It calls to GetAtomInfo to find out if the element exist. The function will return carbon for CF", whereas  IsAtom would return californium
SaveToFile void TEString File
bool Text
Saves the data to a file. The Text parameters specifies if the data should be written in a text or binary format.

An example:

TLog *Log;
int __cdecl main(int argc, char* argv[])
{
    TEString LogFile = TEFiles::ExtractFilePath(argv[0]);
    LogFile += "log.dat";
    Log = new TLog(LogFile);
    TAtomsInfo *AI = new TAtomsInfo(Log->BaseDir + "ptablex.dat", true);
    Log->ConsoleMode = true;

    TEString Msg;
    TSPoint *SP;
    TIPattern Pattern(AI);
    TCHNExp CHN(AI);
    char Bf[100];
    printf("\r\nCHN, IDIST TEST");
    printf("\r\nThe program calculates isotope distribution and elemental analysis for a given formula.");
    printf("\r\n(c) 2004, O.V. Dolomanov");
    printf("\r\n");
repeat:
    Msg = "";
    printf("\r\nPlease enter a chemical formula:>");
    scanf("%s", Bf);

    Pattern.Calc(Bf, Msg, true, 0.5);
    if( Msg.Length() )
    {
        if( Log->YNQuestion("Wrong Formula. Repeat?") == IDYES )
            goto repeat;
    }
    printf("\r\nTen most itense peaks in isotope distribution:");
    if( Pattern.Points->Count() )
    {
        for( int i=0; i < min(10, Pattern.Points->Count()); i++ )
        {
            SP = (TSPoint*)Pattern.Points->Item(i);
                printf("\r\n%f \t %f", SP->X, SP->Y);
        }
    }
    CHN.LoadFromExpression(Bf, Msg);
    printf("\r\nSumm formula: "); printf("%s", CHN.SummFormula(" ").Data() );
    printf("\r\nMol weight : "); printf("%f", CHN.MolWeight(Msg) );
    printf("\r\nComposition : "); printf("%s", CHN.Composition().Data() );
    if( Log->OCQuestion("Repeat?") == IDOK )
        goto repeat;
    delete AI;
    delete Log;
    return 0;

}
 

© Oleg V. Dolomanov, 2004
Last Updated 2004.03.30