Package for reading of .xyz files and constructing of molecular graphs from atomic coordinates.
Project description
xyz2graph
A lightweight Python package for reading XYZ files and creating interactive molecular visualizations. Convert molecular structures into 3D visualizations using Plotly or analyze them as NetworkX graphs.
Features
- Read and parse XYZ molecular structure files
- Generate interactive 3D molecular visualizations using Plotly
- Convert molecular structures to NetworkX graphs for analysis
- Command-line interface for quick visualizations
Installation
pip install xyz2graph
Requirements
- Python 3.8+
- NumPy
- NetworkX
- Plotly
Usage
Python API
from xyz2graph import MolGraph
from plotly.offline import plot
# Create molecular graph and read XYZ file
mg = MolGraph()
mg.read_xyz('molecule.xyz')
print(mg) # e.g., "MolGraph(H20: 3 atoms, 2 bonds)"
print(mg.formula()) # e.g., "H20"
# Generate interactive 3D visualization
fig = mg.to_plotly()
plot(fig)
# Convert to NetworkX graph for analysis
G = mg.to_networkx()
Jupyter Notebook
from xyz2graph import MolGraph
from plotly.offline import init_notebook_mode, iplot
# Initialize Plotly for notebook
init_notebook_mode(connected=True)
# Create and display molecular visualization
mg = MolGraph()
mg.read_xyz('molecule.xyz')
fig = mg.to_plotly()
iplot(fig)
Command Line Interface
Quickly visualize molecules from XYZ files:
# Save visualization as HTML
xyz2graph molecule.xyz
# Specify output file
xyz2graph molecule.xyz --output visualization.html
# Open directly in browser
xyz2graph molecule.xyz --browser
Customization
Customize atomic properties for visualization:
mg = MolGraph()
# Customize atomic radius
mg.set_element_radius('C', 0.75)
# Customize element color
mg.set_element_color('O', 'red')
# Set default color for unlisted elements
mg.set_default_color('pink')
Examples
Example XYZ files can be found in the examples
directory.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use xyz2graph in your research, please cite:
@misc{xyz2graph,
author = {Zotko, Mykola},
title = {xyz2graph: Molecular Structure Visualization},
year = {2018},
publisher = {GitHub},
url = {https://github.com/zotko/xyz2graph}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xyz2graph-3.0.3.tar.gz
.
File metadata
- Download URL: xyz2graph-3.0.3.tar.gz
- Upload date:
- Size: 664.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff7cca3d530e0f8aab153829ac8002db37a3e9fa26aa2b47fc8931678f084cab |
|
MD5 | cf2de9898de78c5d539b107ef0f96f87 |
|
BLAKE2b-256 | 0ca8a340e4a5aefd0520a4c0323f06f1d10368386767688f87e3f1386ee47d50 |
File details
Details for the file xyz2graph-3.0.3-py3-none-any.whl
.
File metadata
- Download URL: xyz2graph-3.0.3-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd6151f934b7eb120200ccd6b79ec6129c85fa1efdca58a88c5518b32b520859 |
|
MD5 | fbb66379b7e6fdd3ca0ec1e5308b7c16 |
|
BLAKE2b-256 | b58f1fc5afb280972a66176d38294e9fa90d8e2e67f75059f9d139781d27ecb9 |