Batch files#
Put one SMILES per line in a text file. An empty line gets an empty output line, so line N of the output belongs to line N of the input.
$ cat molecules.smi
CCO
c1ccccc1
F[Xe]F
$ orthonym --batch molecules.smi
CCO ethanol
c1ccccc1 benzene
F[Xe]F
Each output line is the SMILES, a tab, and the name; the name is empty for a line that gets none, so line N of the output belongs to line N of the input. The reason for each such line, with its limit code, goes to the error stream:
F[Xe]F UNSUPPORTED_ELEMENT: inorganic compound (not supported)
--on-failure label writes the label in the name column instead, and --on-failure raise gives the line ERROR: and the reason and ends the run with status 1 (see Declines). Write the lines to a file with --output, and add --verbose for a count at the end:
$ orthonym --batch molecules.smi --output names.txt --verbose
Processed 3 SMILES, 0 errors, 1 unnamed
Output written to: names.txt
A line that RDKit cannot read does not stop the run. It gets ERROR: and the reason, and the exit status is then 1:
$ orthonym --batch bad.smi
CCO ethanol
not-a-smiles ERROR: Invalid SMILES: not-a-smiles
CC(=O)O acetic acid
MOL and SDF files#
--sdf FILE names every record of a MOL or SDF file, as --batch names the lines of a text file: one output line per record, in the order of the file. The first column is the SMILES that was named (a CXSMILES for a record with an AND or OR stereo group), then a tab and the name:
$ orthonym --sdf molecules.sdf
C[C@@H](N)C(=O)O (2R)-2-aminopropanoic acid
C/C=C\C (2Z)-but-2-ene
CC[C@H](C)O |&1:2| rac-(2R)-butan-2-ol
The stereo is the file’s own. RDKit reads the tetrahedral centres from the wedge bonds (or from the coordinates of a 3D record) and the double bonds from the coordinates. A double bond marked ‘either’, or drawn crossed, stays open. A V3000 record keeps its AND and OR stereo collections, and the name states them (rac-, rel-). The chiral flag of a V2000 record is not read: as in the standard InChI, the configurations are absolute. Many writers, RDKit among them, set the flag to 0 also for a structure of known configuration; state a racemate with a V3000 AND collection. Orthonym then drops the coordinates, so nothing is perceived from them again while the structure is named.
A record that RDKit cannot read, or whose SMILES does not hold it, gets the line <record N>, which is reported as an unreadable line of --batch is (ERROR: and exit status 1), and its number and the reason go to the error stream. A record with no atoms gets an empty line and a message. --sdf takes the options of --batch (--output, --emit-tier, --provenance, --on-failure, --jobs, --time-limit).
A time limit for each structure#
A few structures take a long time (a large molecule, a cage ring system: some need half a minute or more), and in a long file they hold up everything behind them. --time-limit SECONDS gives each line at most that long. A line that is not named in time is a line with no name, in its own place, and the run goes on with the next one:
$ cat slow.smi
CCO
CC1C(C=CC(C2CCC2CN3CC4(CCCC5=C4C=CC(=C5)Cl)COC6=C3C=C(C=C6)C(=O)N=[S-](=O)C1C(=O)N(C)OC7=NN(C=C7C(=O)N)C)OC)OC(=O)N(C)C
c1ccccc1
$ orthonym --batch slow.smi --time-limit 5
CCO ethanol
CC1C(C=CC(C2CCC2CN3CC4(CCCC5=C4C=CC(=C5)Cl)COC6=C3C=C(C=C6)C(=O)N=[S-](=O)C1C(=O)N(C)OC7=NN(C=C7C(=O)N)C)OC)OC(=O)N(C)C
c1ccccc1 benzene
The error stream has the reason of the second line, with the code TIME_LIMIT:
CC1C(C=CC(C2CCC2CN3CC4(CCCC5=C4C=CC(=C5)Cl)COC6=C3C=C(C=C6)C(=O)N=[S-](=O)C1C(=O)N(C)OC7=NN(C=C7C(=O)N)C)OC)OC(=O)N(C)C TIME_LIMIT: no name within the time limit of 5 s
The limit follows the other options for a structure that gets no name:
--on-failure empty(the default): an empty name, and the reason<SMILES><tab>TIME_LIMIT: no name within the time limit of 5 son the error stream.--on-failure label: the labelno name within the time limit of 5 sin the name column.--on-failure raise: the line getsERROR: [TIME_LIMIT] no name within the time limit of 5 s, the run goes on, and it ends with status1, as for any other limit.--provenance: the row has"name": null,"tier": "abstain"and"limit_code": "TIME_LIMIT", and--on-failuredoes not change it. With--confidencethe score column isunverifiedand the engine columnTIME_LIMIT.
--verbose adds the number of lines that ran out of time, which are also counted as unnamed (as errors with --on-failure raise). --output writes the same lines to the file. The limit is for naming: the start-up of the run (the Java machine, OPSIN’s tables, about 1.5 s) is paid before the first limit begins and is not counted against the first line.
The next line is named exactly as it is named without the limit: the limit puts back everything a cut-off naming had set, and the run builds a new namer. A limit that never expires changes nothing; a 50-line file gives the same output with --time-limit 600 as without it. The limit also works for one SMILES (orthonym "SMILES" --time-limit 30), with the output of a structure that gets no name and, with --on-failure raise, status 1.
How the limit stops a naming. It is a timer signal (SIGALRM) whose handler stops the naming at the next Python statement, and a lost signal is raised again every 0.1 s. A call that is already running inside the Java machine (OPSIN, the stereo labeller) or inside RDKit cannot be stopped from Python and finishes first, so a line can take a little longer than the limit. Measured on 168 structures (150 random drug-like molecules from PubChem, 6 large oligosaccharides, 12 macrocycles and cage ring systems) at limits of 0.05, 0.1, 0.25, 0.5 and 1 s, 268 of 840 runs ran out of time. They stopped 1.1 ms after the limit in the middle, within 10 ms for 99 in 100, and within 57 ms at worst. In 12 of them a call into the Java machine was running when the limit expired, and the extra time was at most 11 ms. The calls into the Java machine in the naming of a 90-second peptide (389 of them) lasted 0.42 s at most (the first call of the process, which starts the Java machine and which the start-up makes before the first limit) and 1.7 s together. A single call that lasts much longer is not covered by these numbers: OPSIN needs about 2 s to read a made-up name of 3,600 characters, and the limit of that line is exceeded by what is left of the call. A call that lasts minutes was met once (a polyphenylene of 37 benzene rings, GitHub issue 121, in the RDKit search that matches a ring fragment onto its canonical re-parse); the naming no longer makes it for rings joined by bonds. For one SMILES (not --batch), a call that is still running 5 s after the limit ends the run with the output of any other timeout; a batch has no such end, and the lines after a call that does not return wait for it. Where no timer signal exists (Windows) or orthonym is called from a thread other than the main one, the run says so once on the error stream and names every line without a limit.
Many processes at once#
Name many structures in one run, not one orthonym call per structure: a new process costs about 2.2 s to start (the Java machine, OPSIN’s tables), and a running one names a typical drug-like molecule in about 0.13 s. --jobs N names the lines of a batch file in N processes at once:
$ orthonym --batch molecules.smi --jobs 8 --output names.txt
The output is the same as with one process, line for line and in the same order, and so is the error stream. Each process starts its own Java machine and needs about 270 MB of memory. Measured on 400 random PubChem structures on a 60-core machine: 8 processes name them 6.4 times as fast as one, and 30 processes 12.5 times as fast. When the naming of a structure ends its process (a crash inside RDKit or the Java machine), the structures that were being named at that moment (at most N) are named again, each in a process of its own; a line whose structure ends that process too gets ERROR:, and the run goes on with status 1. --time-limit gives each line the same limit in every process. A time limit depends on how busy the machine is, so a line that needs about as long as the limit can run out of time in one run and not in another, with or without --jobs.
Tiers and provenance rows#
A batch run has the same default as one SMILES: the best-effort tier, that is the verified PIN when the strict path builds one and otherwise a systematic name. The default prints one note on the error stream at the end of the run, once however many lines got a name below pin_verified, and none when no line did. --emit-tier works as it does for one SMILES. This file has a molecule with no PIN, which --emit-tier pin leaves without a name:
$ cat wide.smi
CCO
CC(C)(C(=O)Nc1cccc(F)c1)N1CCC(c2nc(-c3cc4ccccc4o3)cs2)CC1
F[Xe]F
$ orthonym --batch wide.smi
CCO ethanol
CC(C)(C(=O)Nc1cccc(F)c1)N1CCC(c2nc(-c3cc4ccccc4o3)cs2)CC1 2-{4-[4-(1-benzofuran-2-yl)-1,3-thiazol-2-yl]piperidin-1-yl}-N-(3-fluorophenyl)-2-methylpropanamide
F[Xe]F
$ orthonym --batch wide.smi --emit-tier pin
CCO ethanol
CC(C)(C(=O)Nc1cccc(F)c1)N1CCC(c2nc(-c3cc4ccccc4o3)cs2)CC1
F[Xe]F
A line that gets no name at the tier you chose follows --on-failure. The whole file is named with one Orthonym instance, as in the Python loop below.
--provenance puts the row of The provenance row in the second column, on one line, in place of the name. It has the same keys as the row for one SMILES, and --on-failure does not change it: a line with no name has limit_code and, with --emit-tier other than pin, null as its name. The row carries the tier, so the note is not printed.
$ orthonym --batch wide.smi --provenance
CCO {"name": "ethanol", "tier": "pin_verified", "is_pin": true, ...}
--confidence works with every tier; the line has the name, the score and the handler (without --emit-tier the note is printed when a name is below pin_verified). It cannot be combined with --provenance, because a row has no coverage score. orthonym stops with a usage error and status 2.
The flags that look inside the naming of one structure cannot be combined with --batch: --validation-stats, --dispatch-stats, --engine-only, --dump-tree and --format (which only sets the layout of --dump-tree). orthonym stops with a usage error and status 2, before the file is read, and names the flags it refused. To look inside the naming of one line, run orthonym on that SMILES with the flag.
For rows with more keys, or to make the choices of the Orthonym constructor that the command line does not offer, loop in Python with one Orthonym instance:
import json
from orthonym import Orthonym
namer = Orthonym(general_fallback=True) # the valid tier
with open("molecules.smi") as src, open("rows.jsonl", "w") as out:
for line in src:
smiles = line.strip()
if smiles:
out.write(json.dumps({"smiles": smiles, **namer.name_tiered(smiles)}) + "\n")