xyz

package module
v0.0.0-...-c095f45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2015 License: MIT Imports: 8 Imported by: 0

README

xyz

GoDoc

Package xyz implements access to read and write xyz content.

Install

go get github.com/larzconwell/xyz

License

MIT licensed, see here

Documentation

Overview

Package xyz implements access to read and write xyz content.

References:

http://openbabel.org/wiki/XYZ_%28format%29

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrElementSymbol occurs when the symbol is unrecognized.
	ErrElementSymbol = errors.New("xyz: elements atomic symbol is unrecognized")
	// ErrElementNumber occurs when the given atomic number is out of range.
	ErrElementNumber = errors.New("xyz: elements atomic number is out of range")
)
View Source
var (
	// ErrInvalidMolecule is returned when the given molecule input isn't valid.
	ErrInvalidMolecule = errors.New("xyz: input is not a valid molecule")
)

Functions

This section is empty.

Types

type Atom

type Atom struct {
	Element Element
	X       float64
	Y       float64
	Z       float64
}

Atom contains the element and it's cartesian coords.

func (*Atom) String

func (atom *Atom) String() string

String prints the atom in its literal form.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads and decodes lists of molecules.

Example
package main

import (
	"bytes"
	"fmt"
	"github.com/larzconwell/xyz"
	"io"
)

func main() {
	buf := bytes.NewBufferString(`5
Methane molecule
C  0.000000  0.000000  0.000000
H  0.000000  0.000000  1.089000
H  1.026719  0.000000 -0.363000
H -0.513360 -0.889165 -0.363000
H -0.513360  0.889165 -0.363000
3
Water molecule
O  0.00000 0.00000 0.00000
H  0.75700 0.58600 0.00000
H -0.75700 0.58600 0.00000`)

	decoder := xyz.NewDecoder(buf)
	for {
		molecule, err := decoder.Decode()
		if err == io.EOF {
			break
		}
		if err != nil {
			panic(err)
		}

		fmt.Println(molecule.Comment)
		for _, atom := range molecule.Atoms {
			fmt.Println(atom.Element, atom.X, atom.Y, atom.Z)
		}
	}
}
Output:

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

NewDecoder returns a decoder reading from the given reader.

The decoder is buffered and may read data beyond the molecule data requests.

func (*Decoder) Decode

func (decoder *Decoder) Decode() (*Molecule, error)

Decode decodes the next molecule in the reader.

type Element

type Element int

Element is a single elements atomic number.

func ParseElement

func ParseElement(data []byte) (Element, error)

ParseElement parses the element from a slice of bytes. It recognizes both atomic numbers and atomic symbols.

func (Element) String

func (el Element) String() string

String returns the symbol for the element.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes and encodes lists of molecules.

Example
package main

import (
	"bytes"
	"github.com/larzconwell/xyz"
	"io"
	"os"
)

func main() {
	molecule := &xyz.Molecule{
		Comment: "Water molecule",
		Atoms: []*xyz.Atom{
			{8, 0.00000, 0.00000, 0.00000},
			{1, 0.75700, 0.58600, 0.00000},
			{1, -0.075700, 0.58600, 0.00000},
		},
	}

	var buf bytes.Buffer
	encoder := xyz.NewEncoder(&buf)
	err := encoder.Encode(molecule)
	if err != nil {
		panic(err)
	}

	io.Copy(os.Stdout, &buf)
}
Output:

func NewEncoder

func NewEncoder(writer io.Writer) *Encoder

NewEncoder creates an encoder writing to writer.

func (*Encoder) Encode

func (encoder *Encoder) Encode(molecule *Molecule) error

Encode encodes the given molecule writing to the writer.

type Molecule

type Molecule struct {
	Comment string
	Atoms   []*Atom
}

Molecule contains the atoms that make it up.

func (*Molecule) String

func (molecule *Molecule) String() string

String prints the molecule in its literal format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL