PHPackages                             chemstrucml/csml-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chemstrucml/csml-parser

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chemstrucml/csml-parser
=======================

PHP parser and SVG renderer for Chemical Structure Markup Language (CSML)

00PHPCI passing

Since Apr 11Pushed 1mo agoCompare

[ Source](https://github.com/ChemStrucML/CSML-PHP)[ Packagist](https://packagist.org/packages/chemstrucml/csml-parser)[ RSS](/packages/chemstrucml-csml-parser/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

CSML Parser for PHP
===================

[](#csml-parser-for-php)

A PHP 8.4+ package that parses [Chemical Structure Markup Language (CSML)](https://github.com/ChemStrucML/CSML) documents and renders them as SVG images.

CSML is an XML-based markup language for describing molecular structures with full topological, geometric, and repeating-unit information. This package provides the reference PHP implementation for parsing and visualizing CSML documents.

Installation
------------

[](#installation)

```
composer require chemstrucml/csml-parser
```

### Requirements

[](#requirements)

- PHP 8.4 or higher
- `ext-simplexml`
- `ext-dom`
- `ext-libxml`

Quick Start
-----------

[](#quick-start)

```
use ChemStrucML\Csml\CsmlRenderer;

$renderer = new CsmlRenderer();

// Render from a file
$svg = $renderer->renderFile('benzene.csml');

// Render from a string
$svg = $renderer->renderString('

');

// Save to file
file_put_contents('molecule.svg', $svg);
```

Usage
-----

[](#usage)

### Parse and Render Separately

[](#parse-and-render-separately)

```
use ChemStrucML\Csml\CsmlRenderer;

$renderer = new CsmlRenderer();

// Parse to inspect the document model
$document = $renderer->parse($csmlString);

echo $document->version;                    // "0.1"
echo $document->molecules[0]->name;         // "Benzene"
echo count($document->molecules[0]->atoms); // 6

// Render to SVG
$svg = $renderer->render($document);
```

### Custom Rendering Configuration

[](#custom-rendering-configuration)

```
use ChemStrucML\Csml\CsmlRenderer;
use ChemStrucML\Csml\Config\RenderConfig;

$config = new RenderConfig(
    bondLength: 80.0,           // Bond length in SVG pixels (default: 60.0)
    bondWidth: 2.0,             // Stroke width (default: 1.5)
    fontSize: 16.0,             // Atom label font size (default: 14.0)
    fontFamily: 'monospace',    // Font family (default: 'Arial, Helvetica, sans-serif')
    padding: 30.0,              // SVG padding (default: 20.0)
    showAllCarbons: false,      // Show carbon labels in skeletal mode (default: false)
    showImplicitHydrogens: true, // Show implicit H labels (default: true)
    useColoredAtoms: true,      // CPK coloring for atoms (default: true)
    backgroundColor: 'white',   // SVG background (default: 'transparent')
);

$renderer = new CsmlRenderer(config: $config);
$svg = $renderer->renderFile('molecule.csml');
```

### Using the Parser Directly

[](#using-the-parser-directly)

```
use ChemStrucML\Csml\Parser\XmlParser;

$parser = new XmlParser();
$document = $parser->parseFile('molecule.csml');

foreach ($document->molecules as $molecule) {
    echo "Molecule: {$molecule->name}\n";
    echo "  Atoms: " . count($molecule->atoms) . "\n";
    echo "  Bonds: " . count($molecule->bonds) . "\n";
    echo "  Rings: " . count($molecule->rings) . "\n";
}
```

Supported CSML Features
-----------------------

[](#supported-csml-features)

FeatureElementsStatusAtoms``, ``SupportedBonds``, ``SupportedRing systems``, ``SupportedGroups &amp; fragments``, ``, ``, ``SupportedRepeat units``, ``, ``SupportedBranching``SupportedCopolymers``SupportedCoordinates``, ``SupportedMetadata``SupportedImplicit hydrogens`implicit-h="auto"`SupportedStereochemistry`chirality`, `stereo` attributesParsedGeometry constraints``, ``, ``Parsed### Bond Rendering Styles

[](#bond-rendering-styles)

- **Single, double, triple** bonds with proper parallel line offset
- **Aromatic** rings with inscribed circle
- **Wedge** bonds (filled triangle for stereo-up)
- **Hatch** bonds (dashed lines for stereo-down)
- **Dashed** bonds (hydrogen bonds, partial bonds)

### Atom Rendering

[](#atom-rendering)

The renderer follows **skeletal formula** conventions by default:

- Carbon atoms are not labeled (unless they carry a charge, isotope, or explicit label)
- Non-carbon atoms display their element symbol with CPK coloring (O = red, N = blue, S = yellow, etc.)
- Implicit hydrogens are shown as subscripts (e.g. NH, OH, NH₂)
- Charges are rendered as superscripts (e.g. O⁻, NH₃⁺)

CSML Examples
-------------

[](#csml-examples)

### Benzene

[](#benzene)

```

```

### 1-Hexanol

[](#1-hexanol)

```

```

### Naphthalene (Fused Rings)

[](#naphthalene-fused-rings)

```

```

Why CSML?
---------

[](#why-csml)

FeatureCSMLSMILESMOL/SDFCMLInChIHuman-readableYesYesNoYesNoPolymer repeat unitsYesNoPartialNoNoCopolymer patternsYesNoNoNoNoReusable fragmentsYesNoNoPartialNoExtensible (namespaces)YesNoNoYesNoEnd-group specificationYesNoNoNoNoCSML separates **topology** (what is connected to what) from **geometry** (angles, lengths) and from **presentation** (how to draw it), making it uniquely suited for polymer science, materials engineering, and structural chemistry applications where existing formats fall short.

License
-------

[](#license)

MIT

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance58

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1edb79f2a1fcd61016ec9a5b65183e1f6e7852a4b1f9a5bd6f69c6160366f22c?d=identicon)[renfordt](/maintainers/renfordt)

---

Top Contributors

[![renfordt](https://avatars.githubusercontent.com/u/699163?v=4)](https://github.com/renfordt "renfordt (8 commits)")

### Embed Badge

![Health badge](/badges/chemstrucml-csml-parser/health.svg)

```
[![Health](https://phpackages.com/badges/chemstrucml-csml-parser/health.svg)](https://phpackages.com/packages/chemstrucml-csml-parser)
```

###  Alternatives

[dev-lnk/moonshine-builder

Project builder for MoonShine

255.4k](/packages/dev-lnk-moonshine-builder)[efficiently/jquery-laravel

This package provides jQuery and the jQuery-ujs driver for your Laravel &gt;= 6 application.

1311.2k1](/packages/efficiently-jquery-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
