5
$\begingroup$

I would like to convert SMILES strings into file names. There are many characters to avoid in file names, i.e. \/:*?"<>| or maybe even []()^ #%&!@:+={}'~ (see discussion) for convenience. I would like to escape such characters that appear in SMILES. However, I could not see a list of allowed characters for SMILES to decide on how to escape them. There might be also some existing convention to do this for databases, so I am all ears for any help.

An alternative is using InChIkeys but since they are not human readable, I want to avoid that option.

Edit: I am mainly interested in small organic molecules with less than 20 atoms.

$\endgroup$
  • 2
    $\begingroup$ Are the SMILES strings not going to make awfully long file names for anything but the most trivial of molecules? Long file names might be allowed now, but can cause issues with some software / systems $\endgroup$ – NotEvans. May 12 '17 at 18:28
  • $\begingroup$ I am mainly interested in small organic molecules, (less than 20 atoms) so length won't be a problem. Thanks for pointing it out, I'll edit the question to specify it. $\endgroup$ – Armut May 12 '17 at 18:45
  • $\begingroup$ So you like to filter out, char wise, all but 0-9 and A-Z, and collapse this string -- with the examples on the site given by you and on en.wikipedia.org/wiki/…, it sounds like a suitable question for the code golfers (codegolf.stackexchange.com). Awk, grep ... $\endgroup$ – Buttonwood May 12 '17 at 18:58
  • 2
    $\begingroup$ InChI keys are more appropriate, since they are in fact hashes. But there is always many ways how to repesent single structure in SMILES string, and there are also multiple ways how to normalize those strings. $\endgroup$ – mykhal May 12 '17 at 20:53
  • 2
    $\begingroup$ Maybe a better question to ask is: why are you doing this? $\endgroup$ – Zhe May 12 '17 at 21:36
2
$\begingroup$

From my experience, the only characters that have been a problem are '/', '\', and '#'. I replace them with 'z', 'x', '^' respectively. It's not a convention but just something I've come up with. If you were to use the file name in a command, '(', ')', '$' would also need to be escaped.

$\endgroup$
2
$\begingroup$

I've used base64 encoding in the past for escaping SMILES strings for use as filenames.

$\endgroup$
  • 1
    $\begingroup$ I might be wrong here, but that is equally unreadable as an InChIkey, and it doesn't even have a fixed length. Otherwise I don't understand your answer (which is more like a comment to begin with). $\endgroup$ – Martin - マーチン Dec 5 '17 at 9:41
  • $\begingroup$ I read the original question as the OP looking for a way of escaping the SMILES string for use as a filename. For sure, base64 encoding is not human readable. $\endgroup$ – Noel O'Boyle Dec 5 '17 at 15:12
1
$\begingroup$

I personally find SMILES quite unreadable, even for only small compounds. I think they are even less readable when performing substitutions. Given the vast amount of special characters they use, I do not think they are a good way to create a naming scheme.

An alternative is using InChIkeys but since they are not human readable, I want to avoid that option.

While that is true, InChI strings are human readable, especially for small molecules. In principle only the layers need to be separated by something other than / (underscores would do that).

Other problematic characters are *;?+() which do not fit in [0-9a-zA-Z-.,_], and you would have to find ways around them when using in scripts.

I am mainly interested in small organic molecules with less than 20 atoms.

If you are really only interested in molecules with less than 20 atoms, general nomenclature should be the easiest to comprehend, and should yield reasonably short file names. For these you probably only have to worry about spaces.

$\endgroup$
  • $\begingroup$ The question is about SMILES. $\endgroup$ – Noel O'Boyle Dec 5 '17 at 15:15
  • $\begingroup$ @NoelO'Boyle Exactly, that's why I am writing that SMILES is a bad way to generate filenames and then offer alternatives. $\endgroup$ – Martin - マーチン Dec 5 '17 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.