SMARTS lets you select structures that contain a particular molecular motif. This example searches a compound CSV for C(=O)OH and C(=O)O⁻ separately, then writes the results beside the original compound IDs.

A public question about examining substructures in a list of SMILES illustrates the task: decide which part of a molecule matters, then find it across a list of structures.

Define the motifs

These two patterns follow the official Daylight SMARTS examples:

COOH:  [CX3](=O)[OX2H1]
COO⁻:  [CX3](=O)[O-]

The first finds an oxygen bearing one hydrogen and bonded to a carbonyl carbon. The second looks for a negatively charged oxygen at that position. The output columns acid_match and anion_match record 1 for a match and 0 otherwise. A structure containing both motifs has 1 in both columns.

The selection is defined by these exact substructures. Carbamic and carbonic acid derivatives with the same motifs can also match. Inspect the selected structures against the class definition and neighboring atoms relevant to your study.

Search every structure in the CSV

Save compounds.csv and carboxyl_csv.py in the same directory. The input uses source_id for the compound ID and smiles for the structure.

Open that directory in a terminal. On macOS or Linux, run:

python3 -m venv .venv
.venv/bin/python -m pip install "chematic==1.1.2"
.venv/bin/python carboxyl_csv.py compounds.csv

These commands require Python; the examples were checked on macOS arm64 with Python 3.13.6. On Windows, use py -m venv .venv for the first line and replace .venv/bin/python with .\.venv\Scripts\python.exe. After package installation, reading the CSV and searching the structures happen on your computer.

The script searches the supplied SMILES directly. If your workflow calls for salt removal or charge changes first, choose a standardization policy and retain those settings with the search results.

Select matching rows

This sample output was checked with the published chematic Python package v1.1.2:

source_id  name            acid_match  anion_match
CMP001     acetic acid     1           0
CMP002     ethanol         0           0
CMP003     aspirin         1           0
CMP004     ethyl acetate   0           0
CMP005     sodium acetate  0           1

Acetic acid and aspirin match the COOH pattern. Sodium acetate matches the COO⁻ pattern. Ethyl acetate is an ester and matches neither.

Open carboxyl-report.csv in a spreadsheet and filter for acid_match=1 or anion_match=1. Use status=ok to select processed rows. The file also retains both patterns, the original SMILES, and the input record number, so you can trace a selected compound back to the query and source record.

Download the example output CSV and execution record. Check the query against these five compounds before substituting your own list.