/* cansmi_tutorial.c */ /********************************************************************** * This source code is public domain, and may be freely distributed, * * modified, and used for any purpose. IT COMES WITH ABSOLUTELY NO * * WARRANTY OF ANY KIND. * **********************************************************************/ /***************************************************************************** * cansmi.c -- the "Hello World" of Daylight toolkit programming. */ #include #include /*** This defines Daylight constants such as "dt_Handle" and function prototypes. These are required for Daylight toolkit programs. ***/ #include "dt_smiles.h" int main(int argc, char *argv[]) { /*** A dt_Handle is one of the special datatypes used by the Daylight toolkit. All Daylight toolkit functions use these types; in this case a dt_Handle is the ID of an object within the toolkit. The value has no meaning on it's own, but is used to refer to an object. ***/ dt_Handle mol; int lencan; char *cansmi, line[1000]; while (gets(line)) { /*** dt_smilin() parses a SMILES string and attempts to make a molecule or reaction object from it. If it succeeds it returns the ID of the new object that was created, which we store in a local variable. If it fails the function returns the special constant "NULL_OB" ***/ mol = dt_smilin(strlen(line), line); if (mol == NULL_OB) fprintf(stderr, "ERROR: Can't parse \"%s\"\n", line); else { /*** The dt_cansmiles() function asks the molecule (or reaction) to compute it's canonical SMILES and return it. If it fails it returns the "invalid string", which in the C language is NULL. ***/ cansmi = dt_cansmiles(&lencan, mol, 0); if (cansmi && (lencan > 0)) printf("%.*s\n", lencan, cansmi); else fprintf(stderr, "ERROR: Can't make unique SMILES for \"%s\"\n", line); /*** dt_dealloc() releases the resources used by the object. Generally a good idea. Once an object has been deallocated, referring to it by it's handle is an error. ***/ dt_dealloc(mol); } } return 0; }