From: Nina J. <ni...@ac...> - 2005-09-18 14:42:50
|
Hi all, I am suggesting following minor fixes to MDLWriter class. These does not affect its general behaviour, but handle a couple of more specific cases. 1) Writing a property block of a molecule in SDF file. Properties as obtained object.getProperties() can be any type, thus writer.write((String)sdFields.get(element)) gives ClasCastException if the property has type different than String. Using sdFields.get(element).toString() method should resolve the issue. MDLWriter.java <code> public void writeMolecule(Molecule molecule, boolean[] isVisible) throws Exception { ..... //write sdfields, if any if(sdFields!=null){ Set set = sdFields.keySet(); Iterator iterator = set.iterator(); while (iterator.hasNext()) { Object element = iterator.next(); //writer.write("> <"+(String)element+">"); //replace with the line below writer.write("> <"+element.toString()+">"); writer.newLine(); //writer.write((String)sdFields.get(element)); writer.write(sdFields.get(element).toString()); writer.newLine(); writer.newLine(); } } </code> 2) Property block of some SDF files (e.g. at http://ligand.info/) does not conform entirely to the specification, lacking the required blank line between end of property data to the next data header. This confuses MDLReader and it reads only the first compound, assuming the rest of the file as a property data. I would suggest throwing an exception if $$$$ marker is encountered while reading the property block. <code> private ChemFile readChemFile(ChemFile chemFile) throws CDKException { .... //while ((line = input.readLine()) != null && // line.trim().length() > 0) { while ((line = input.readLine()) != null && (line.trim().length() > 0)) { if (line.equals("$$$$")) throw new CDKException("Expecting data line here, but found end of molecule!"); </code> 3) Really minor correction, since the second line of an SDF record is generally ignored ;) <code> // instead of writer.write(" CDK\n"); /* From CTX spec * This line has the format: * IIPPPPPPPPMMDDYYHHmmddSSssssssssssEEEEEEEEEEEERRRRRR * (FORTRAN: A2<--A8--><---A10-->A2I2<--F10.5-><---F12.5--><-I6-> ) * User's first and last initials (l), program name (P), date/time (M/D/Y,H:m), dimensional codes (d), scaling factors (S, s), energy (E) if modeling program input, internal registry number (R) if input through MDL form. * A blank line can be substituted for line 2. */ writer.write(" CDK "); writer.write(new SimpleDateFormat("M/d/y,H:m",Locale.US).format( Calendar.getInstance(TimeZone.getDefault()).getTime()) ); writer.write('\n'); </code> Regards, Nina -- ------------------------------------------------------------------ Assoc. Prof. Dr. Nina Nikolova-Jeliazkova * * Institute for Parallel Processing * * Bulgarian Academy of Sciences * IST Foundation * Acad. G. Bonchev St 25-A * The Bulgarian NREN * 1113 Sofia, Bulgaria * * Tel: +3592 9796616 * * ICQ: 10705013 http://www.ist.bg www: http://ambit.acad.bg/nina ------------------------------------------------------------------ PGP Public Key http://cert.acad.bg/pgp-keys/keys/nina-nikolova-0xEEABA669.asc 8E99 8BAD D804 1A43 27B7 7F87 CF04 C7D1 EEAB A669 ------------------------------------------------------------------ |