Main Page | Data Structures | File List | Data Fields | Globals

smilesCompound.c

Go to the documentation of this file.
00001 /* just some information about this file */
00002 #define SMILESCOMPOUND_VERSION  "1.4.0"
00003 #define SMILESCOMPOUND_DATE     "16-Mar-2004"
00004 
00005 /* structures and typedefs */
00006 
00007 /** @file
00008 * @anchor SmilesCompound
00009 * Fault-tolerant structure to store the data of one SMILES, SMIRKS or SMARTS.
00010 * <BR>
00011 * This structure stores the data of one SMILES, SMIRKS or SMARTS.
00012 * <BR>
00013 * The structure is created with @ref SmilesCompound_create, destroyed with @ref SmilesCompound_destroy
00014 * and displayed with @ref SmilesCompound_display. With SmilesCompound_set<i>nameOfMember</i> and
00015 * SmilesCompound_get<i>nameOfMember</i> the values of the individual members of the structure
00016 * @ref SmilesCompound could be set or gotten. @ref SmilesCompound_identical checks if the @c smiles
00017 * of two SmilesCompounds are identical (returns @ref BOOLEAN_TRUE) or non-identical (returns
00018 * @ref BOOLEAN_FALSE). Non-Identity is only true if both @c smiles are canonical.
00019 * <BR>
00020 * If a @ref SmilesCompound is created with a SMILES, member @c smiles stores the canonical SMILES of
00021 * that compound to allow for a idenditcal check (@ref SmilesCompound_identical). Canonical SMIRKS are
00022 * not supported by the Daylight Toolkit. Hence, the uniqueness check fails, if two reactions share
00023 * the same semantics but differ lexicographically. The same holds for SMARTS.
00024 * <BR>
00025 * The name of a SMILES, SMIRKS or SMARTS is stored in a @ref StringArray. Thus, it is possible to store
00026 * more than one name for a given SMILES, SMIRKS or SMARTS. Detailed information about accessibility of
00027 * the name is provided by the documentation of the respective functions (@ref SmilesCompound_setName,
00028 * @ref SmilesCompound_addName and @ref SmilesCompound_getStringArrayOfNames).
00029 * <BR>
00030 * @attention
00031 * If the member @c smiles or the name of a SMILES, SMIRKS or SMART is set (@ref SmilesCompound_setName,
00032 * @ref SmilesCompound_addName and @ref SmilesCompound_setSmiles) the provided string is @b copied via
00033 * @c strncpy. Hence, the string provided as an argument has to be freed by the caller of the function.
00034 * 
00035 * <BR><B>Description of the members:</B><BR><BR>
00036 *       @c smiles - string containing the SMILES, SMIRKS or SMARTS of one compound<BR>
00037 * @c counter - counts the occurence of a specific SMILES (does <b>not</b> work for SMIRKS and SMARTS as they cannot be converted to a canonical representation)<BR>
00038 * @c sAPtr - pointer on structure @ref StringArray that stores one or more names of the SMILES, SMIRKS or SMARTS<BR>
00039 * @c moleculeHandle - dt_Handle on a Daylight object that correspoinds to @c smiles<BR>
00040 * @c fingerprintHandle - dt_Handle on a Daylight fingerprint object that corresponds to @c smiles<BR>
00041 * @author Uli Fechner
00042 * @version 28/11/2003 - Uli Fechner - 1.0.0 - initial release
00043 * @version 02/12/2003 - Uli Fechner - 1.0.2 - added the member @c counter and the functions @ref
00044 * SmilesCompound_getCounter, @ref SmilesCompound_setCounter, @ref SmilesCompound_increaseCounter
00045 * and @ref SmilesCompound_decreaseCounter; added the member @c moleculeHandle and the functions
00046 * @ref SmilesCompound_getMoleculeHandle and @ref SmilesCompound_setMoleculeHandle
00047 * @version 03/12/2003 - Uli Fechner - 1.0.3 - added support for write out of errors revieved from
00048 * dt_smilinerrors (@ref SmilesCompound_create); added function @ref SmilesCompound_identical
00049 * @ version 04/12/2003 - Uli Fechner - 1.0.4 - @ref SmilesCompound_create stores now the canonical
00050 * SMILES to allow for identical check between two SmilesCompouns; small change in @ref
00051 * SmilesCompound_display
00052 * @version 08/12/2003 - Uli Fechner - 1.0.5 - changes in @ref SmilesCompound_create to allow for the
00053 * checking of a successful creation
00054 * @version 10/12/2003 - Uli Fechner - 1.1.0 - changed the storage of a compound name from char* to
00055 * @ref StringArray; modified function @ref SmilesCompound_create, @ref SmilesCompound_destroy, @ref
00056 * SmilesCompound_display, @ref SmilesCompound_setName, @ref SmilesCompound_addName and 
00057 * SmilesCompound_getName accordingly; change in @ref SmilesCompound_identical: if two SmilesCompounds
00058 * are identical the @ref StringArray of the source SmilesCompound is concatenated to the @ref
00059 * StringArray of the target compound
00060 * @version 17/12/2003 - Uli Fechner - 1.2.0 - changed the name of SmilesCompound_getName to
00061 * @ref SmilesCompound_getStringArrayOfNames; complete re-write of @ref SmilesCompound_setSmiles
00062 * (changed return type from void to int); added @ref SmilesCompound_copy
00063 * @version 19/12/2003 - Uli Fechner - 1.2.1 - added function @ref SmilesCompound_removeFromArrayOfNames;
00064 * major bugifx in @ref SmilesCompound_identical
00065 * @version 29/01/2004 - Tina Grabowski - 1.3.0 - major change: added support for SMARTS; corresponding
00066 * changes in @ref SmilesCompound_create and @ref SmilesCompound_setSmiles
00067 * @version 16/03/2004 - UF - 1.4.0 - added member fingerprint and the functions 
00068 * SmilesCompound_getFingerprint and SmilesCompound_setFingerprint; renamed member @c daylightHandle
00069 * to @c moleculeHandle in the complete file; renamed functions SmilesCompound_get/setDaylightHandle to
00070 * SmilesCompound_get/setMoleculeHandle accordingly
00071 * @@code
00072 */
00073 typedef struct
00074 {
00075         char* smiles;
00076         int counter;
00077         StringArray_Ptr sAPtr;
00078         dt_Handle moleculeHandle;
00079         dt_Handle fingerprintHandle;
00080 } SmilesCompound;
00081 /** @endcode */
00082 
00083 /** A pointer to structure @ref SmilesCompound is assigned the name @c SmilesCompound_Ptr. */
00084 typedef SmilesCompound* SmilesCompound_Ptr;
00085 
00086 /* defines */
00087 
00088 /** Boolean variables are simulated with the defines BOOLEAN_FALSE and BOOLEAN_TRUE.
00089 *
00090 * @author Uli Fechner
00091 * @version 03/12/2003 - Uli Fechner - initial release
00092 */
00093 #ifndef BOOLEAN_FALSE
00094 #define BOOLEAN_FALSE 0
00095 #endif
00096 
00097 /** Boolean variables are simulated with the defines BOOLEAN_FALSE and BOOLEAN_TRUE.
00098 *
00099 * @author Uli Fechner
00100 * @version 03/12/2003 - Uli Fechner - initial release
00101 */
00102 #ifndef BOOLEAN_TRUE
00103 #define BOOLEAN_TRUE 1
00104 #endif
00105 
00106 /* define 'functions' */
00107 
00108 /** The member @c counter of structure @ref SmilesCompound is increased by one.
00109 *
00110 * @param scPtr pointer on the structure @ref SmilesCompound the member @c counter belongs to
00111 * @author Uli Fechner
00112 * @version 02/12/2003 - Uli Fechner - initial release
00113 */
00114 #ifndef SmilesCompound_increaseCounter
00115 #define SmilesCompound_increaseCounter( scPtr ) \
00116         ( (scPtr->counter)++)
00117 #endif
00118 
00119 /** The member @c counter of structure @ref SmilesCompound is decreased by one.
00120 *
00121 * @param scPtr pointer on the structure @ref SmilesCompound the member @c counter belongs to
00122 * @author Uli Fechner
00123 * @version 02/12/2003 - Uli Fechner - initial release
00124 */
00125 #ifndef SmilesCompound_decreaseCounter
00126 #define SmilesCompound_decreaseCounter( scPtr ) \
00127         ( (scPtr->counter)--)
00128 #endif
00129 
00130 /* function prototypes */
00131 
00132 SmilesCompound_Ptr SmilesCompound_create( char* const name, char* const smiles, const int daylight_type, \
00133         FILE* errorLogFile );
00134 
00135 void SmilesCompound_destroy( void* scPtr );
00136 
00137 void SmilesCompound_display( void* scPtr, FILE* outputStream );
00138 
00139 SmilesCompound_Ptr SmilesCompound_copy( const SmilesCompound_Ptr scPtr );
00140 
00141 int SmilesCompound_identical( const void* scPtr1, const void* scPtr2 );
00142 
00143 void SmilesCompound_setName( const SmilesCompound_Ptr scPtr, const char* const name );
00144 
00145 void SmilesCompound_addName( const SmilesCompound_Ptr scPtr, const char* const name );
00146 
00147 StringArray_Ptr SmilesCompound_getStringArrayOfNames( const SmilesCompound_Ptr scPtr );
00148 
00149 int SmilesCompound_removeFromArrayOfNames( const SmilesCompound_Ptr scPtr, const char* name );
00150 
00151 int SmilesCompound_setSmiles( const SmilesCompound_Ptr scPtr, char* smiles, const int daylight_type, \
00152         FILE* errorLogFile );
00153 
00154 char* SmilesCompound_getSmiles( const SmilesCompound_Ptr scPtr );
00155 
00156 void SmilesCompound_setCounter( const SmilesCompound_Ptr scPtr, const int counter );
00157 
00158 int SmilesCompound_getCounter( const SmilesCompound_Ptr scPtr );
00159 
00160 void SmilesCompound_setMoleculeHandle( const SmilesCompound_Ptr scPtr, const dt_Handle moleculeHandle );
00161 
00162 dt_Handle SmilesCompound_getMoleculeHandle( const SmilesCompound_Ptr scPtr );
00163 
00164 /* functions */
00165 
00166 /** Creates a @ref SmilesCompound structure.
00167 *
00168 * The structure @ref SmilesCompound is created. The memory of the structure itself and of its members
00169 * is allocated automatically. The name and the SMILES, SMIRKS or SMARTS string have to be provided
00170 * as arguments.
00171 * <BR>
00172 * The function returns a SmilesCompound_Ptr on the newly created structure @ref SmilesCompound or @ref
00173 * BOOLEAN_FALSE if the creation of the @ref SmilesCompound fails somehow. Thus, the caller of this
00174 * function should check for the return value @ref BOOLEAN_FALSE, to guarantee the successful creation
00175 * of the @ref SmilesCompound.
00176 * <BR>
00177 * Parameter @c daylight_type may have one of the following three values:
00178 * @li @ref DAYLIGHT_SMILES to indicate that @c smiles is a SMILES
00179 * @li @ref DAYLIGHT_SMIRKS to indicate that @c smiles is a SMIRKS
00180 * @li @ref DAYLIGHT_SMARTS to indicate that @c smiles is a SMARTS
00181 * <BR>
00182 * @attention
00183 * The provided parameters @c name and @c smiles are copied. @c name and @c smiles are <b>not</b> freed
00184 * afterwards. This has to be done by the caller of this function. A Daylight object of the SMILES, SMIRKS
00185 * or SMARTS that is represented by the char* @c smiles is automatically created with the function
00186 * dt_smilin, dt_smirkin and dt_smartin, respectively.
00187 *
00188 * @param name the name (i.e. identifier) of the SMILES, SMIRKS or SMARTS
00189 * @param smiles the SMILES, SMIRKS or SMARTS string of the compound
00190 * @param daylight_type variable to indicate whether smiles contains SMILES, SMIRKS or SMARTS
00191 * @param errorLogFile file pointer on the error log file
00192 * @retval SmilesCompound_Ptr pointer on the newly created structure @ref SmilesCompound or BOOLEAN_FALSE if the creation fails somehow
00193 * @author Uli Fechner
00194 * @version 28/11/2003 - Uli Fechner - initial release
00195 * @version 02/12/2003 - Uli Fechner - added support for member @c counter and @c moleculeHandle;
00196 * added boolean parameter transform
00197 * @version 03/12/2003 - Uli Fechner - added parameter @c errorLogFile to write out errors revieved
00198 * from dt_smilinerrors
00199 * @version 04/12/2003 - Uli Fechner - the counter is set to one during creation; the smiles is either
00200 * the canonical SMILES generated with dt_cansmiles in case of a SMILES or the original input in case
00201 * of a SMIRK
00202 * @version 08/12/2003 - Uli Fechner - if dt_cansmiles or dt_smirkin is not able to return a valid
00203 * SMILES or transform object the function returns BOOLEAN_FALSE
00204 * @version 10/12/2003 - Uli Fechner - reflect the change of name storage (name is no longer stored in
00205 * a char* but in a @ref StringArray)
00206 * @version 29/01/2004 - Tina Grabowski - major change: added support for reading SMARTS
00207 */
00208 SmilesCompound_Ptr SmilesCompound_create( char* const name, char* const smiles, const int daylight_type, \
00209         FILE* errorLogFile )
00210 {
00211         SmilesCompound_Ptr scPtr; /* points on the newly created SmilesCompound */
00212         char* canonicalSmiles; /* stores the result of the dt_cansmiles function */
00213         dt_Handle sequenceErrorHandle, stringObjectHandle; /* used to process the dt_smilin errors */
00214         dt_Integer length; /* needed by function dt_cansmiles and dt_smilinerrors */
00215         char* copyOfName; /* storage for a copy of the function parameter name */
00216 
00217         if( !( scPtr = calloc( 1, sizeof( SmilesCompound ) ) ) )
00218                 MemoryError( "scPtr", "SmilesCompound_create" );
00219                 
00220         scPtr->sAPtr = StringArray_create( );
00221         if( name != NULL )
00222         {
00223                 if( !( copyOfName = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00224                         MemoryError( "copyOfName", "SmilesCompound_create" );   
00225                 strncpy( copyOfName, name, strlen( name ) + 1 );        
00226                 StringArray_addElement( scPtr->sAPtr, copyOfName );
00227         }
00228         scPtr->counter = 1;
00229         
00230         /* differentiating between SMILES, SMIRKS and SMARTS */
00231         if( daylight_type == DAYLIGHT_SMILES )
00232         {
00233                 /* generating the daylight molecule object and the canonical SMILES
00234                 the canonical SMILES is then stored in scPtr->smiles */
00235                 scPtr->moleculeHandle = dt_smilin( strlen( smiles ), smiles );
00236                 canonicalSmiles = dt_cansmiles( &length, scPtr->moleculeHandle, 1 );
00237                 if( length != -1 )
00238                 {
00239                         //fprintf( stderr, "length = %d\n", length );
00240                         if( !( scPtr->smiles = calloc( length + 1, sizeof( char ) ) ) )
00241                                 MemoryError( "scPtr->smiles", "SmilesCompound_create" );
00242                         strncpy( scPtr->smiles, canonicalSmiles, length + 1 );
00243                 }
00244                 else
00245                 {
00246                         StringArray_destroy( scPtr->sAPtr );
00247                         free( scPtr );
00248                         return BOOLEAN_FALSE;
00249                 }
00250         }
00251         /* we are dealing with SMIRKS */
00252         if( daylight_type == DAYLIGHT_SMIRKS )
00253         {
00254                 scPtr->moleculeHandle = dt_smirkin( strlen( smiles ), smiles );
00255                 if( scPtr->moleculeHandle != NULL_OB )
00256                 {
00257                         /* scPtr->smiles is assigned to the input SMIRKS */
00258                         if( !( scPtr->smiles = calloc( strlen( smiles ) + 1, sizeof( char ) ) ) )
00259                                 MemoryError( "scPtr->smiles", "SmilesCompound_create" );        
00260                         strncpy( scPtr->smiles, smiles, strlen( smiles ) + 1 ); 
00261                 }
00262                 else
00263                 {
00264                         StringArray_destroy( scPtr->sAPtr );
00265                         free( scPtr );
00266                         return BOOLEAN_FALSE;
00267                 }
00268         }
00269         /* we are dealing with SMARTS */
00270         if( daylight_type == DAYLIGHT_SMARTS )
00271         {
00272                 scPtr->moleculeHandle = dt_smartin( strlen( smiles ), smiles );
00273                 if( scPtr->moleculeHandle != NULL_OB )
00274                 {
00275                         /* scPtr->smiles is assigned to the input SMARTS */
00276                         if( !( scPtr->smiles = calloc( strlen( smiles ) + 1, sizeof( char ) ) ) )
00277                                 MemoryError( "scPtr->smiles", "SmilesCompound_create" );        
00278                         strncpy( scPtr->smiles, smiles, strlen( smiles ) + 1 ); 
00279                 }
00280                 else
00281                 {
00282                         StringArray_destroy( scPtr->sAPtr );
00283                         free( scPtr );
00284                         return BOOLEAN_FALSE;
00285                 }
00286         }
00287                 
00288         /* writing the dt_smilin errors to the error log file */
00289         sequenceErrorHandle = dt_smilinerrors();
00290         while( ( stringObjectHandle = dt_next( sequenceErrorHandle ) ) != NULL_OB )
00291                 fprintf( errorLogFile, "%s\n", dt_stringvalue( &length, stringObjectHandle ) );         
00292         
00293         return scPtr;
00294 }
00295 
00296 
00297 /** Destroys a @ref SmilesCompound structure.
00298 *
00299 * The structure @ref SmilesCompound the pointer @c scPtr refers to is destroyed. The memory of the
00300 * structure itself and of its members is freed automatically.
00301 *
00302 * @param scPtr pointer on structure @ref SmilesCompound that should be destroyed
00303 * @author Uli Fechner
00304 * @version 28/11/2003 - Uli Fechner - initial release
00305 * @version 02/12/2003 - Uli Fechner - added support for the member @c moleculeHandle
00306 * @version 10/12/2003 - Uli Fechner - reflect the change of name storage (name is no longer stored in
00307 * a char* but in a @ref StringArray)
00308 */
00309 void SmilesCompound_destroy( void* scPtr )
00310 {
00311         SmilesCompound_Ptr castedScPtr;
00312         castedScPtr = (SmilesCompound_Ptr) scPtr;
00313         
00314         if( castedScPtr != NULL )
00315         {
00316                 if( castedScPtr->sAPtr != NULL )
00317                         StringArray_destroy( castedScPtr->sAPtr );
00318                 if( castedScPtr->smiles != NULL )
00319                         free( castedScPtr->smiles );
00320                 if( castedScPtr->moleculeHandle != NULL_OB )
00321                         dt_dealloc( castedScPtr->moleculeHandle );
00322                 free( castedScPtr );
00323         }
00324         else
00325         {
00326                 fprintf( stderr, "\n\nERROR: Function 'SmilesCompound_destroy' could not destroy a structure\n" );
00327                 fprintf( stderr, "'SmilesCompound' that has not been created before!\n" );
00328                 AbortProgram;
00329         }
00330 }
00331 
00332 /** Displays a structure @ref SmilesCompound.
00333 *
00334 * The structure @ref SmilesCompound the pointer @c scPtr refers to is displayed on the FILE* @c
00335 * outputStream.
00336 *
00337 * @param scPtr pointer on the structure @ref SmilesCompound that should be displayed
00338 * @param outputStream FILE* on the stream the output should be sent to
00339 * @author Uli Fechner
00340 * @version 28/11/2003 - Uli Fechner - initial release
00341 * @version 02/12/2003 - Uli Fechner - added support for member @c counter and @c moleculeHandle
00342 * @version 04/12/2003 - Uli Fechner - member @c counter is now displayed regardless of the value;
00343 * revoked support for @c moleculeHandle as from now on the canonical smiles is stored in @c smiles
00344 * @version 10/12/2003 - Uli Fechner - removed output of dt_typename; changed order of output; reflect
00345 * the change of name storage (name is no longer stored in a char* but in a @ref StringArray)
00346 */
00347 void SmilesCompound_display( void* scPtr, FILE* outputStream )
00348 {
00349         SmilesCompound_Ptr castedScPtr;
00350         castedScPtr = (SmilesCompound_Ptr) scPtr;
00351                 
00352         fprintf( outputStream, "%s", SmilesCompound_getSmiles( scPtr ) );
00353         fprintf( outputStream, "\t%d", SmilesCompound_getCounter( scPtr ) );
00354         if( StringArray_getNumberOfElements( castedScPtr->sAPtr ) != 0 )
00355         {
00356                 fprintf( outputStream, "\t" );
00357                 StringArray_display( castedScPtr->sAPtr, outputStream );
00358         }
00359         fprintf( outputStream, "\n" );
00360 }
00361 
00362 /** Returns a deepcopy of the @ref SmilesCompound @c scPtr.
00363 *
00364 * @param scPtr pointer on the @ref SmilesCompound that is copied
00365 * @retval SmilesCompound_Ptr a deepcopy of the @ref SmilesCompound @c scPtr
00366 * @author Uli Fechner
00367 * @version 17/12/2003 - Uli Fechner - initial release
00368 */
00369 SmilesCompound_Ptr SmilesCompound_copy( const SmilesCompound_Ptr scPtr )
00370 {
00371         SmilesCompound_Ptr copyOfScPtr; /* copy of the SmilesCompound scPtr */  
00372         char* copyOfSmilesString; /* storage for a copy of the smiles string scPtr->smiles */
00373 
00374         if( !( copyOfScPtr = calloc( 1, sizeof( SmilesCompound ) ) ) )
00375                 MemoryError( "copyOfScPtr", "SmilesCompound_copy" );
00376                 
00377         if( scPtr->smiles != NULL )
00378         {
00379                 if( !( copyOfSmilesString = calloc( strlen( scPtr->smiles ) + 1, sizeof( char ) ) ) )
00380                         MemoryError( "copyOfSmilesString", "SmilesCompound_copy" );
00381                 strncpy( copyOfSmilesString, scPtr->smiles, strlen( scPtr->smiles ) + 1 );
00382         }
00383         copyOfScPtr->counter = scPtr->counter;
00384         copyOfScPtr->sAPtr = StringArray_copy( scPtr->sAPtr );
00385         copyOfScPtr->moleculeHandle = dt_copy( scPtr->moleculeHandle );
00386         
00387         return copyOfScPtr;
00388 }
00389 
00390 /** Checks if the two SmilesCompounds @c scPtr1 and @c scPtr2 have identical char* @c smiles.
00391 *
00392 * If the two SmilesCompounds @c scPtr1 and @c scPtr2 have identical char* @c smiles, the @c counter
00393 * of @c scPtr1 is increased by one and a copy of the @ref StringArray of @c scPtr2 is concatenated
00394 * to the @ref StringArray @c sAPtr.
00395 *
00396 * @param scPtr1 pointer on the first structure @ref SmilesCompound
00397 * @param scPtr2 pointer on the second structure @ref SmilesCompound
00398 * @retval int BOOLEAN_TRUE if the smiles of @c scPtr1 and @c scPtr2 are identical, BOOLEAN_FALSE otherwise
00399 * @author Uli Fechner
00400 * @version 03/12/2003 - Uli Fechner - initial release
00401 * @version 10/12/2003 - Uli Fechner - if the @c smiles of two compounds are identical, a copy of
00402 * StringArray of @c scPtr2 is concatenated to the StringArray of @c scPtr1
00403 * @version 19/12/2003 - Uli Fechner - major bugifx: the counter is now updated correctly
00404 */
00405 int SmilesCompound_identical( const void* scPtr1, const void* scPtr2 )
00406 {
00407         if( strcmp( ( (SmilesCompound_Ptr) scPtr1)->smiles, ( (SmilesCompound_Ptr) scPtr2)->smiles ) != 0 )
00408                 return BOOLEAN_FALSE;
00409         
00410         SmilesCompound_setCounter( ( SmilesCompound_Ptr ) scPtr1, \
00411                 SmilesCompound_getCounter( ( SmilesCompound_Ptr ) scPtr1 ) + \
00412                 SmilesCompound_getCounter( ( SmilesCompound_Ptr ) scPtr2 ) );
00413         StringArray_concatenate( ( (SmilesCompound_Ptr) scPtr1)->sAPtr, ( (SmilesCompound_Ptr) scPtr2)->sAPtr );
00414         return BOOLEAN_TRUE;
00415 }
00416 
00417 /** The name of structure @ref SmilesCompound is set to @c name as the only name.
00418 *
00419 * The member @c sAPtr is destroyed and newly created with @c name as the only name. Thus, all
00420 * names that were stored previously are lost. If @c name should be added to the list of names,
00421 * function @ref SmilesCompound_addName has to be used.
00422 *
00423 * @attention
00424 * The provided parameter @c name is copied. @c name is not freed afterwards. This has to be done by
00425 * the caller of this function. @c name is not set as the name of @c scPtr if it is NULL.
00426 *
00427 * @param scPtr pointer on the structure @ref SmilesCompound the member @c name is set
00428 * @param name name of the compound
00429 * @author Uli Fechner
00430 * @version 28/11/2003 - Uli Fechner - initial release
00431 * @version 10/12/2003 - Uli Fechner - complete rewrite to reflect the change of name storage (name
00432 * is no longer stored in a char* but in a @ref StringArray)
00433 */
00434 void SmilesCompound_setName( const SmilesCompound_Ptr scPtr, const char* const name )
00435 {
00436         char* tempString;
00437         
00438         if( scPtr->sAPtr != NULL )
00439                 StringArray_destroy( scPtr->sAPtr );
00440         
00441         scPtr->sAPtr = StringArray_create( );
00442         if( strlen( name ) != 0 )
00443         {
00444                 if( !( tempString = calloc( strlen( name ) + 1, sizeof( char ) ) ) )
00445                         MemoryError( "tempString", "SmilesCompound_setName" );  
00446                 strncpy( tempString, name, strlen( name ) + 1 );
00447                 StringArray_addElement( scPtr->sAPtr, tempString );
00448         }
00449 }
00450 
00451 /** @c name is added to the list of names of structure @ref SmilesCompound.
00452 *
00453 * If @c name should be set as the only name of @c scPtr, function @ref SmilesCompound_setName has
00454 * to be used. If names are added with this function they are preceeded by a tab character to separate
00455 * the individual names from each other in the output.
00456 *
00457 * @attention
00458 * The provided parameter @c name is copied. @c name is not freed afterwards. This has to be done by
00459 * the caller of this function. @c name is not added to the list of names of @c scPtr if it is NULL.
00460 *
00461 * @param scPtr pointer on the structure @ref SmilesCompound the member @c name is added
00462 * @param name name of the compound
00463 * @author Uli Fechner
00464 * @version 10/12/2003 - Uli Fechner - initial release
00465 */
00466 void SmilesCompound_addName( const SmilesCompound_Ptr scPtr, const char* const name )
00467 {
00468         char* tempString;
00469         
00470         if( scPtr->sAPtr == NULL )
00471                 scPtr->sAPtr = StringArray_create( );
00472         
00473         if( strlen( name ) != 0 )
00474         {
00475                 if( !( tempString = calloc( strlen( name ) + 2, sizeof( char ) ) ) )
00476                         MemoryError( "tempString", "SmilesCompound_addName" );
00477                 sprintf( tempString, "\t" );
00478                 strncat( tempString, name, strlen( name ) + 1 );
00479                 StringArray_addElement( scPtr->sAPtr, tempString );
00480         }
00481 }
00482 
00483 /** The member @c sAPtr (contains the name(s)) of structure @ref SmilesCompound is returned.
00484 *
00485 * @param scPtr pointer on the structure @ref SmilesCompound the member @c name belongs to
00486 * @retval StringArray_Ptr pointer on structure StringArray that contains the name(s) of the compound
00487 * @author Uli Fechner
00488 * @version 28/11/2003 - Uli Fechner - initial release
00489 * @version 10/12/2003 - Uli Fechner - reflect the change of name storage (name is no longer stored in
00490 * a char* but in a @ref StringArray)
00491 * @version 17/12/2003 - Uli Fechner - changed the function name from SmilesCompound_getName to
00492 * SmilesCompound_getStringArrayOfNames
00493 */
00494 StringArray_Ptr SmilesCompound_getStringArrayOfNames( const SmilesCompound_Ptr scPtr )
00495 {
00496         return scPtr->sAPtr;
00497 }
00498 
00499 /** All names of @c scPtr that are identical to @c name are removed from the @ref StringArray that contains the names.
00500 *
00501 * @attention
00502 * The @c counter of the respective @ref SmilesCompound referred to by @c scPtr is automatically adjusted
00503 * as follows: newValue = oldValue - occurrencesOfName.
00504 *
00505 * @param scPtr pointer on the structure @ref SmilesCompound that contains the array of names
00506 * @param name the name that is looked for in the @ref StringArray of @c scPtr
00507 * @retval int the number of occurences of @c name in @c scPtr's array of names
00508 * @author Uli Fechner
00509 * @version 19/12/2003 - Uli Fechner - initial release
00510 */
00511 int SmilesCompound_removeFromArrayOfNames( const SmilesCompound_Ptr scPtr, const char* name )
00512 {
00513         int occurrencesOfName;
00514         
00515         occurrencesOfName = StringArray_removeElement( SmilesCompound_getStringArrayOfNames( scPtr ), name );
00516         SmilesCompound_setCounter( scPtr, SmilesCompound_getCounter( scPtr ) - occurrencesOfName );
00517         
00518         return occurrencesOfName;
00519 }
00520 
00521 /** The member @c smiles of structure @ref SmilesCompound is set.
00522 *
00523 * If the function is called the previous @c smiles and @c moleculeHandle are destroyed. A new Daylight
00524 * object is created with dt_smilin, dt_smirkin or dt_smartin if a SMILES, SMIRKS or SMARTS is provided,
00525 * respectively. In case of a SMILES the given @c smiles is converted to a canonical representation with
00526 * dt_cansmiles. If dt_smilin or dt_cansmiles fails somehow, the complete @ref SmilesCompound is destroyed
00527 * and the function returns @ref BOOLEAN_FALSE. If everything goes smoothly @ref BOOLEAN_TRUE is returned.
00528 *
00529 * @attention
00530 * The provided parameter @c smiles is copied. @c smiles is not freed afterwards. This has to be done by
00531 * the caller of this function.<BR>
00532 *
00533 * @param scPtr pointer on the structure @ref SmilesCompound the member @c smiles is set
00534 * @param smiles SMILES, SMIRKS or SMARTS string
00535 * @param daylight_type variable to indicate whether smiles contains SMILES, SMIRKS or SMARTS
00536 * @param errorLogFile file pointer on the error log file
00537 * @author Uli Fechner
00538 * @version 28/11/2003 - Uli Fechner - initial release
00539 * @version 17/12/2003 - Uli Fechner - re-written from scratch; now, provides consistency between @c
00540 * smiles and @c moleculeHandle
00541 * @version 29/01/2004 - Tina Grabowski - major change: added support for SMIRKS and SMARTS as @ref
00542 *                       SmilesCompound_create does
00543 */
00544 int SmilesCompound_setSmiles( const SmilesCompound_Ptr scPtr, char* smiles, const int daylight_type, \
00545         FILE* errorLogFile)
00546 {
00547         dt_Integer lengthCanSmiles; /* required by dt_cansmiles */
00548         dt_Integer lengthSmilinError; /* required by dt_stringvalue */
00549         char* canonicalSmiles; /* stores the canonical SMILES returned by dt_smilin */
00550         dt_Handle sequenceErrorHandle, stringObjectHandle; /* used to process the dt_smilin errors */
00551         
00552         if( scPtr->smiles != NULL )
00553                 free( scPtr->smiles );  
00554         if( scPtr->moleculeHandle != NULL_OB )
00555                 dt_dealloc( scPtr->moleculeHandle );
00556         
00557         /* we are dealing with a SMILES */
00558         if( daylight_type == DAYLIGHT_SMILES )
00559         {
00560                 /* generating the daylight molecule object and the canonical SMILES
00561                 the canonical SMILES is then stored in scPtr->smiles */
00562                 scPtr->moleculeHandle = dt_smilin( strlen( smiles ), smiles );
00563                 canonicalSmiles = dt_cansmiles( &lengthCanSmiles, scPtr->moleculeHandle, 1 );
00564                 /* testing whether the call of dt_cansmiles was successful */
00565                 if( lengthCanSmiles != -1 )
00566                 {
00567                         if( !( scPtr->smiles = calloc( lengthCanSmiles + 1, sizeof( char ) ) ) )
00568                                 MemoryError( "scPtr->smiles", "SmilesCompound_setSmiles" );
00569                         strncpy( scPtr->smiles, canonicalSmiles, lengthCanSmiles + 1 );
00570                 }
00571                 else
00572                 {
00573                         SmilesCompound_destroy( scPtr );
00574                         return BOOLEAN_FALSE; //FUNCTION EXITS HERE
00575                 }
00576         }
00577         /* we are dealing with a SMIRKS */
00578         if( daylight_type == DAYLIGHT_SMIRKS )
00579         {
00580                 scPtr->moleculeHandle = dt_smirkin( strlen( smiles ), smiles );
00581                 if( scPtr->moleculeHandle != NULL_OB )
00582                 {
00583                         /* scPtr->smiles is assigned to the input SMIRKS */
00584                         if( !( scPtr->smiles = calloc( strlen( smiles ) + 1, sizeof( char ) ) ) )
00585                                 MemoryError( "scPtr->smiles", "SmilesCompound_setSmiles" );     
00586                         strncpy( scPtr->smiles, smiles, strlen( smiles ) + 1 ); 
00587                 }
00588                 else
00589                 {
00590                         StringArray_destroy( scPtr->sAPtr );
00591                         free( scPtr );
00592                         return BOOLEAN_FALSE; //FUNCTION EXITS HERE
00593                 }
00594         }
00595         /* we are dealing with a SMARTS */
00596         if( daylight_type == DAYLIGHT_SMARTS )
00597         {
00598                 /* generating the daylight object; the SMARTS is then stored in scPtr->smiles */
00599                 scPtr->moleculeHandle = dt_smartin( strlen( smiles ), smiles );
00600                 /* testing whether the call of dt_smartin was successful */
00601                 if( scPtr->moleculeHandle != NULL_OB )
00602                 {
00603                         if( !( scPtr->smiles = calloc( strlen( smiles )+ 1, sizeof( char ) ) ) )
00604                                 MemoryError( "scPtr->smiles", "SmilesCompound_setSmiles" );
00605                         strncpy( scPtr->smiles, smiles, strlen( smiles ) + 1 );
00606                 }
00607                 else
00608                 {
00609                         SmilesCompound_destroy( scPtr );
00610                         return BOOLEAN_FALSE; //FUNCTION EXITS HERE
00611                 }
00612         }
00613         /* writing the dt_smilin errors to the error log file */
00614         sequenceErrorHandle = dt_smilinerrors();
00615         while( ( stringObjectHandle = dt_next( sequenceErrorHandle ) ) != NULL_OB )
00616                 fprintf( errorLogFile, "%s\n", dt_stringvalue( &lengthSmilinError, stringObjectHandle ) );
00617         
00618         return BOOLEAN_TRUE;
00619 }
00620 
00621 /** The member @c smiles of structure @ref SmilesCompound is returned.
00622 *
00623 * @param scPtr pointer on the structure @ref SmilesCompound the member @c smiles belongs to
00624 * @retval char* SMILES string of the compound
00625 * @author Uli Fechner
00626 * @version 28/11/2003 - Uli Fechner - initial release
00627 */
00628 char* SmilesCompound_getSmiles( const SmilesCompound_Ptr scPtr )
00629 {
00630         return scPtr->smiles;
00631 }
00632 
00633 /** The member @c counter of structure @ref SmilesCompound is set.
00634 *
00635 * @param scPtr pointer on the structure @ref SmilesCompound the member @c counter is set
00636 * @param counter integer value that is assigned to the member @c counter
00637 * @author Uli Fechner
00638 * @version 02/12/2003 - Uli Fechner - initial release
00639 */
00640 void SmilesCompound_setCounter( const SmilesCompound_Ptr scPtr, const int counter )
00641 {
00642         scPtr->counter = counter;
00643 }
00644 
00645 /** The member @c counter of structure @ref SmilesCompound is returned.
00646 *
00647 * @param scPtr pointer on the structure @ref SmilesCompound the member @c counter belongs to
00648 * @retval int value of the member @c counter 
00649 * @author Uli Fechner
00650 * @version 02/12/2003 - Uli Fechner - initial release
00651 */
00652 int SmilesCompound_getCounter( const SmilesCompound_Ptr scPtr )
00653 {
00654         return scPtr->counter;
00655 }
00656 
00657 /** The member @c moleculeHandle of structure @ref SmilesCompound is set.
00658 *
00659 * @param scPtr pointer on the structure @ref SmilesCompound the member @c moleculeHandle is set
00660 * @param moleculeHandle dt_Handle that is assigned to the member @c moleculeHandle
00661 * @author Uli Fechner
00662 * @version 02/12/2003 - Uli Fechner - initial release
00663 */
00664 void SmilesCompound_setMoleculeHandle( const SmilesCompound_Ptr scPtr, const dt_Handle moleculeHandle )
00665 {
00666         scPtr->moleculeHandle = moleculeHandle;
00667 }
00668 
00669 /** The member @c moleculeHandle of structure @ref SmilesCompound is returned.
00670 *
00671 * @param scPtr pointer on the structure @ref SmilesCompound the member @c moleculeHandle belongs to
00672 * @retval dt_Handle value of the member @c moleculeHandle
00673 * @author Uli Fechner
00674 * @version 02/12/2003 - Uli Fechner - initial release
00675 */
00676 dt_Handle SmilesCompound_getMoleculeHandle( const SmilesCompound_Ptr scPtr )
00677 {
00678         return scPtr->moleculeHandle;
00679 }

Generated on Tue Nov 9 16:27:11 2004 for retroflux by doxygen 1.3.6