gochem/main.go
chemistry-software 0841f1190b SDF molfile parser
2024-09-26 13:50:26 +02:00

37 lines
730 B
Go

package main
import (
"fmt"
"os"
"log"
"gitea.boner.be/bdnugget/gochem/gochem"
)
func main() {
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <path_to_molfile>", os.Args[0])
}
filePath := os.Args[1]
molecule, err := gochem.ParseSDF(filePath)
if err != nil {
log.Fatalf("Error parsing SDF file: %v", err)
}
printMolecule(molecule)
}
func printMolecule(mol *gochem.Molecule) {
fmt.Printf("Molecule with %d atoms:\n", mol.NumAtoms)
for _, atom := range mol.Atoms {
fmt.Printf("Atom #%d: %s (%.2f, %.2f, %.2f)\n", atom.Idx, atom.AtomType, atom.X, atom.Y, atom.Z)
fmt.Printf(" Neighbours: ")
for _, neighbour := range atom.Neighbours {
fmt.Printf("%s ", neighbour.AtomType)
}
fmt.Println()
}
}