Skip to main content
← OpenMECP Documentation

write_xyz

Function write_xyz 

Source
pub fn write_xyz(geom: &Geometry, path: &Path) -> Result<()>
Expand description

Writes a molecular geometry to an XYZ file.

The XYZ format is a simple plain-text format for molecular geometries, widely used in chemistry software. It consists of:

  1. Number of atoms
  2. A comment line (empty in this implementation)
  3. Lines for each atom: Element X Y Z

§Arguments

  • geom - The molecular geometry to write
  • path - The path to the output XYZ file

§Returns

Returns Ok(()) on success, or an std::io::Error if file writing fails.

§Examples

use omecp::geometry::Geometry;
use omecp::io;
use std::path::Path;

fn main() -> std::io::Result<()> {
    let elements = vec!["C".to_string(), "H".to_string()];
    let coords = vec![0.0, 0.0, 0.0, 1.0, 0.0, 0.0];
    let geometry = Geometry::new(elements, coords);

    io::write_xyz(&geometry, Path::new("molecule.xyz"))?;
    std::fs::remove_file("molecule.xyz")?;
    Ok(())
}