|
From: Noel O'B. <bao...@gm...> - 2009-06-09 10:52:11
|
2009/6/8 Vincent Favre-Nicolin <vi...@us...>:
> On lundi 8 juin 2009, systemguy wrote:
>
>> Not sure anyone else would care but incorporating Avogadro's supercell
>> builder code would be great for me. I tried working with the code myself
>> but I am not that much of a programmer. I am building some giant
>> supercells and Avogadro takes a long time since it tries to draw the
>> supercell as well as create the file. Command line functionality a la OB
>> would be very helpful (I think this is on the Avogadro to do list
>> eventually).
>
> Although it would be possible to incorporate this in OB, I think such custom
> modifications would much better be done in a scripting language - to avoid too
> many command-line options in OB.
>
> In Python it could begin like this:
> #######
> import pybel
> mol=pybel.readfile("cif","ABENAX.cif").next()
> unitcell = mol.unitcell
> unitcell.FillUnitCell(mol.OBMol)
> for a in mol.atoms:
> print a.OBAtom.x(),a.OBAtom.y(),a.OBAtom.z()
BTW, try a.coords
> # Create new atoms by translation here and add them to mol ?
>
>
> #######
>
> However I got stuck - I can get the fractionnal matrix
> (unitcell.GetFractionalMatrix()) and the cell vectors
> (unitcell.GetCellVectors()), but I can't seem to be able to use them because
> they are swig pointers ? Even unitcell.GetCellVectors()[0].x() ? I'm not used
> to the pybel interface, so maybe someone else has an idea ?
This came up on openbabel-scripting around 26th May.
The Cell Vectors can be accessed as follows by passing in an array of doubles:
cv = mol.unitcell.GetCellVectors()[0]
a = pybel.ob.doubleArray(3)
cv.Get(a)
print a[0], a[1], a[2]
Unfortunately, the matrices are not supported in the current release.
I've added support on the 22x branch in SVN, and put an updated
Windows installer here:
http://www.redbrick.dcu.ie/~noel/tmp/openbabel-python-1.4.1b.py2.5.exe
Once you have the matrix, you can use Get(0,0) to Get(2,2) to access
the elements or else get a vector3 of the row or column (see the C++
API).
It seems like there's a lot of interest in this CIF code. If you can
get a supercell example together, that would be very helpful.
- Noel
|