Category:Scripting

From Avogadro - Free cross-platform molecule editor

Jump to: navigation, search

There are many to use Python in Avogadro. This page gives an overview.

Contents

Introduction

The Avogadro python API resembles the [C++ API] as much as possible. This means that the C++ documentation also applies to python. However, there are some differences which are defined by the following rules.

>>> print atom.atomicNumber
6
>>> atom.atomicNumber = 1
>>> print atom.atomicNumber
1
>>> print molecule.atomPos(0) # print position of atom with id 0
[1.  2.  3.]
>>> molecule.setAtomPos(0, array([0.0, 0.0, 0.0])) 

>>> import Avogadro
>>> import numpy
>>> molecule = Avogadro.Molecule()
>>> atom = molecule.newAtom()
>>> a.pos = numpy.array([1, 2, 3]) # Vector3d != Vector3i !
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    None.None(Atom, numpy.ndarray)
did not match C++ signature:
    None(Avogadro::Atom {lvalue}, Eigen::Matrix<double, 3, 1, 0, 3, 1>)
>>> a.pos = numpy.array([1., 2., 3.]) # valid (note the "." after each number to indicate float/double)

Getting started

Intermediate

Advanced

These topics assume you know how to work with Molecules, Atoms, the GLWidget and other classes previously introduced.

Writing Plugins

Standalone

Pages in category "Scripting"

The following 4 pages are in this category, out of 4 total.

P

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox