Skip to main content

Python bindings for readcon-core CON/convel file parser

Project description

Table of Contents

  1. About
    1. Usage
    2. Design Decisions
      1. FFI Layer
    3. Specification
      1. Single Frames
      2. Multiple Frames
    4. Why use this over readCon?
  2. License

About

Oxidized rust re-implementation of readCon.

Usage

cargo run -- resources/test/sulfolene.con

Design Decisions

The library is designed with the following principles in mind:

  • Lazy Parsing: The ConFrameIterator allows for lazy parsing of frames, which can be more memory-efficient when dealing with large trajectory files.

  • Interoperability: The FFI layer makes the core parsing logic accessible from other programming languages, increasing the library's utility. Currently, a C header is auto-generated along with a hand-crafted C++ interface, following the hourglass design from Metatensor.

FFI Layer

A key challenge in designing an FFI is deciding how data is exposed to the C-compatible world. This library uses a hybrid approach to offer both safety and convenience:

  1. Opaque Pointers (The Handle Pattern): The primary way to interact with frame data is through an opaque pointer, represented as RKRConFrame* in C. The C/C++ client holds this "handle" but cannot inspect its contents directly. Instead, it must call Rust functions to interact with the data (e.g., rkr_frame_get_header_line(frame_handle, ...)). This is the safest and most flexible pattern, as it completely hides Rust's internal data structures and memory layout, preventing ABI breakage if the Rust code is updated.

  2. Transparent #[repr(C)] Structs (The Data Extraction Pattern): For convenience and performance in cases where only the core atomic data is needed, the library provides a function (rkr_frame_to_c_frame) to extract a "lossy" but transparent CFrame struct from an opaque handle. The C/C++ client can directly read the fields of this struct (e.g., my_c_frame->num_atoms). The client takes ownership of this extracted struct and is responsible for freeing its memory.

This hybrid model provides the best of both worlds: the safety and forward-compatibility of opaque handles for general use, and the performance of direct data access for the most common computational tasks.

Specification

Currently this implements the con format specification as written out by eON, so some assumptions are made about the input files, not all of which are currently tested / guaranteed to throw (contributions are welcome for additional sanity checks).

Single Frames

  • The first 9 lines are the header
  • The remaining lines can be inferred from the header

Multiple Frames

Often, as for example when running a Nudged Elastic Band, eON will write out multiple units of con like data into a single file.

  • The con like data have no whitespace between them!

That is we expect:

Random Number Seed
Time
15.345600	21.702000	100.000000
90.000000	90.000000	90.000000
0 0
218 0 1
2
2 2
63.546000 1.007930
Cu
Coordinates of Component 1
   0.63940000000000108    0.90450000000000019    6.97529999999999539 1    0
   3.19699999999999873    0.90450000000000019    6.97529999999999539 1    1
H
Coordinates of Component 2
   8.68229999999999968    9.94699999999999740   11.73299999999999343 0  2
   7.94209999999999550    9.94699999999999740   11.73299999999999343 0  3
Random Number Seed
Time
15.345600	21.702000	100.000000
90.000000	90.000000	90.000000
0 0
218 0 1
2
2 2
63.546000 1.007930
Cu
Coordinates of Component 1
   0.63940000000000108    0.90450000000000019    6.97529999999999539 1    0
   3.19699999999999873    0.90450000000000019    6.97529999999999539 1    1
H
Coordinates of Component 2
   8.85495714285713653    9.94699999999999740   11.16538571428571380 0  2
   7.76944285714285154    9.94699999999999740   11.16538571428571380 0  3

Nothing else. No whitespace or lines between the con entries.

Why use this over readCon?

To learn Rust. Maybe speed.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

readcon-0.2.0.tar.gz (116.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readcon-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl (346.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

File details

Details for the file readcon-0.2.0.tar.gz.

File metadata

  • Download URL: readcon-0.2.0.tar.gz
  • Upload date:
  • Size: 116.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for readcon-0.2.0.tar.gz
Algorithm Hash digest
SHA256 09b7620f15340cd0c1b08261ea4411e5e394050265b574a997902ef875534433
MD5 9b4e48fe0ac3bfbff8eb0cbb92e89d47
BLAKE2b-256 368d136daeadb368771e488453c182a63a893af2b7f29cbead6f24eca22843ba

See more details on using hashes here.

File details

Details for the file readcon-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for readcon-0.2.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00cf2b2c3e5d8d470b11a5ac6ee3ad4ef1c37972878a87b6caf77484dc83df0a
MD5 f12999692088c93c3a0de16d77aea47e
BLAKE2b-256 664a615c2543435f156cc5c869357c49294f2aeb3b6ead56c696cabff20ebb04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page