Esempio n. 1
0
def makeC60():
    """Make the C60 molecule using pyobjcryst."""

    from pyobjcryst.crystal import Crystal
    from pyobjcryst.molecule import Molecule
    from pyobjcryst.scatteringpower import ScatteringPowerAtom

    pi = numpy.pi

    # make a crystal box to put the molecule in
    c = Crystal(1, 1, 1, "P1")
    c.SetName("c60frame")

    # put a molecule inside the box
    m = Molecule(c, "c60")
    c.AddScatterer(m)

    # Create a dummy atom at the center.
    m.AddAtom(0, 0, 0, None, "center")

    # Create the scattering power object for the carbon atoms
    sp = ScatteringPowerAtom("C", "C")
    c.AddScatteringPower(sp)
    sp.SetBiso(0.25)

    # Add the other atoms. They will be named C1, C2, ..., C60.
    for i, l in enumerate(c60xyz.strip().splitlines()):
        x, y, z = map(float, l.split())
        m.AddAtom(x, y, z, sp, "C%i"%(i+1))

    return m
Esempio n. 2
0
def makeC60():
    c = Crystal(100, 100, 100, "P1")
    c.SetName("c60frame")
    m = Molecule(c, "c60")

    c.AddScatterer(m)
    sp = ScatteringPowerAtom("C", "C")
    sp.SetBiso(8*pi*pi*0.003)
    c.AddScatteringPower(sp)

    for i, l in enumerate(c60xyz.strip().splitlines()):
        x, y, z = map(float, l.split())
        m.AddAtom(x, y, z, sp, "C%i"%i)

    return c
Esempio n. 3
0
def makeC60():
    """Make a crystal containing the C60 molecule using pyobjcryst."""
    pi = numpy.pi
    c = Crystal(100, 100, 100, "P1")
    c.SetName("c60frame")
    m = Molecule(c, "c60")

    c.AddScatterer(m)

    sp = ScatteringPowerAtom("C", "C")
    sp.SetBiso(8*pi*pi*0.003)
    #c.AddScatteringPower(sp)

    for i, l in enumerate(c60xyz.strip().splitlines()):
        x, y, z = map(float, l.split())
        m.AddAtom(x, y, z, sp, "C%i"%i)

    return c
Esempio n. 4
0
DB = {
    'Ni_img_file': NI_IMG,
    'Ni_img': load_img(NI_IMG),
    'Kapton_img_file': KAPTON_IMG,
    'Kapton_img': load_img(KAPTON_IMG),
    'Ni_poni_file': NI_PONI,
    'Ni_gr_file': NI_GR,
    'Ni_chi_file': NI_CHI,
    'Ni_fgr_file': NI_FGR,
    'ai': pyFAI.load(NI_PONI),
    'Ni_gr': load_data(NI_GR).T,
    'Ni_chi': load_data(NI_CHI).T,
    'Ni_fgr': load_data(NI_FGR).T,
    'black_img_file': BLACK_IMG,
    'white_img_file': WHITE_IMG,
    'black_img': numpy.zeros((128, 128)),
    'white_img': numpy.ones((128, 128)),
    'Ni_config': NI_CONFIG,
    'Ni_pdfgetter': NI_PDFGETTER,
    'Ni_stru_file': NI_CIF,
    'Ni_stru': NI_CRYSTAL,
    'Ni_stru_molecule': Molecule(NI_CRYSTAL),
    'Ni_stru_diffpy': NI_DIFFPY,
    'ZrP_stru': ZRP_CRYSTAL
}


@pytest.fixture(scope="session")
def db():
    return DB
Esempio n. 5
0
def putAtomsInMolecule(crystal, alist=None, name=None):
    """Place atoms from a crystal into a molecule inside the crystal.

    Selected atoms are put into a new Molecule object, which is then placed
    inside of the Crystal. The atoms are then removed from the crystal. The
    molecule is placed at the center of mass of the moved atoms.

    crystal --  The crystal containing the atoms.
    alist   --  A list of indices or names identifying the atoms. If alist is
                None (default), all atoms from the crystal are placed into a
                molecule.
    name    --  A name for the molecule. If name is None (default), the name
                m_cname will be given, where cname is substituted for the
                crystal's name.

    Raises TypeError if idxlist identifies a non-atom.

    """
    c = crystal

    if name is None:
        name = "m_%s" % c.GetName()

    if alist is None:
        alist = range(c.GetNbScatterer())

    from pyobjcryst.molecule import Molecule
    from pyobjcryst.atom import Atom

    m = Molecule(c, name)

    # center of mass
    cx = cy = cz = 0.0

    # mapping fractional coords back into [0, 1)
    from math import floor

    f = lambda v: v - floor(v)

    scat = []
    for id in alist:
        s = c.GetScatt(id)
        if not isinstance(s, Atom):
            raise TypeError("identifier '%s' does not specify an Atom")
        sp = s.GetScatteringPower()
        scat.append(s)
        x, y, z = map(f, [s.X, s.Y, s.Z])
        x, y, z = c.FractionalToOrthonormalCoords(x, y, z)
        m.AddAtom(x, y, z, sp, s.GetName())

        cx += x
        cy += y
        cz += z

    # Adjust center of mass
    cx /= len(alist)
    cy /= len(alist)
    cz /= len(alist)

    # Remove scatterers from the crystal
    for s in scat:
        c.RemoveScatterer(s)

    # Put the molecule at the CoM
    m.X, m.Y, m.Z = c.OrthonormalToFractionalCoords(cx, cy, cz)

    # Add the molecule to the crystal
    c.AddScatterer(m)

    m.UpdateScattCompList()

    return
Esempio n. 6
0
def putAtomsInMolecule(crystal, alist=None, name=None):
    """Place atoms from a crystal into a molecule inside the crystal.

    Selected atoms are put into a new Molecule object, which is then placed
    inside of the Crystal. The atoms are then removed from the crystal. The
    molecule is placed at the center of mass of the moved atoms.

    crystal --  The crystal containing the atoms.
    alist   --  A list of indices or names identifying the atoms. If alist is
                None (default), all atoms from the crystal are placed into a
                molecule.
    name    --  A name for the molecule. If name is None (default), the name
                m_cname will be given, where cname is substituted for the
                crystal's name.

    Raises TypeError if idxlist identifies a non-atom.

    """
    c = crystal

    if name is None:
        name = "m_%s" % c.GetName()

    if alist is None:
        alist = range(c.GetNbScatterer())

    from pyobjcryst.molecule import Molecule
    from pyobjcryst.atom import Atom
    m = Molecule(c, name)

    # center of mass
    cx = cy = cz = 0.0

    # mapping fractional coords back into [0, 1)
    from math import floor
    f = lambda v: v - floor(v)

    scat = []
    for idx in alist:
        s = c.GetScatt(idx)
        if not isinstance(s, Atom):
            raise TypeError("identifier '%s' does not specify an Atom")
        sp = s.GetScatteringPower()
        scat.append(s)
        x, y, z = map(f, [s.X, s.Y, s.Z])
        x, y, z = c.FractionalToOrthonormalCoords(x, y, z)
        m.AddAtom(x, y, z, sp, s.GetName())

        cx += x
        cy += y
        cz += z

    # Adjust center of mass
    cx /= len(alist)
    cy /= len(alist)
    cz /= len(alist)

    # Remove scatterers from the crystal
    for s in scat:
        c.RemoveScatterer(s)

    # Put the molecule at the CoM
    m.X, m.Y, m.Z = c.OrthonormalToFractionalCoords(cx, cy, cz)

    # Add the molecule to the crystal
    c.AddScatterer(m)

    m.UpdateScattCompList()

    return
Esempio n. 7
0
NI_CHI = load_array(NI_CHI_FILE)
NI_FGR = load_array(NI_FGR_FILE)
NI_CONFIG = PDFConfig()
NI_CONFIG.readConfig(NI_GR_FILE)
NI_PDFGETTER = PDFGetter(NI_CONFIG)
AI = pyFAI.load(NI_PONI_FILE)
MASK = numpy.load(MASK_FILE)
BLACK_IMG = load_img(BLACK_IMG_FILE)
WHITE_IMG = load_img(WHITE_IMG_FILE)
# model file
ZRP_CIF_FILE = resource_filename('tests', 'test_data/ZrP_cif_file.cif')
NI_CIF_FILE = resource_filename("tests", "test_data/Ni_cif_file.cif")
NI_CRYSTAL = loadCrystal(NI_CIF_FILE)
ZRP_CRYSTAL = loadCrystal(ZRP_CIF_FILE)
NI_DIFFPY = loadStructure(NI_CIF_FILE)
NI_MOLECULE = Molecule(NI_CRYSTAL)

DB = {
    'Ni_img_file': NI_IMG_FILE,
    'Ni_img': NI_IMG,
    'Kapton_img_file': KAPTON_IMG_FILE,
    'Kapton_img': KAPTON_IMG,
    'Ni_poni_file': NI_PONI_FILE,
    'Ni_gr_file': NI_GR_FILE,
    'Ni_chi_file': NI_CHI_FILE,
    'Ni_fgr_file': NI_FGR_FILE,
    'ai': AI,
    'Ni_gr': NI_GR,
    'Ni_chi': NI_CHI,
    'Ni_fgr': NI_FGR,
    'black_img_file': BLACK_IMG_FILE,
The C60 molecule are stored in a pyobjcryst object.
"""

from matplotlib.pyplot import plot, show, clf, draw
from diffpy.Structure import Structure
from pyobjcryst.crystal import Crystal
from pyobjcryst.molecule import Molecule
from pyobjcryst.scatteringpower import ScatteringPowerAtom
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator

# load C60 molecule as a diffpy.Structure object
bucky_diffpy = Structure(filename='datafiles/C60bucky.stru')

# convert to an ObjCryst molecule
c60 = Crystal(1, 1, 1, 'P1')
mc60 = Molecule(c60, "C60")
c60.AddScatterer(mc60)
# Create the scattering power object for the carbon atoms
sp = ScatteringPowerAtom("C", "C")
sp.SetBiso(bucky_diffpy[0].Bisoequiv)
for i, a in enumerate(bucky_diffpy):
    cname = "C%i" % (i + 1)
    mc60.AddAtom(a.xyz_cartn[0], a.xyz_cartn[1], a.xyz_cartn[2], sp, cname)

# PDF configuration
cfg = { 'qmax' : 25,
        'rmin' : 0,
        'rmax' : 10.001,
        'rstep' : 0.05,
}
Esempio n. 9
0
import numpy as np
from scipy.optimize import leastsq

from pyobjcryst import loadCrystal
from pyobjcryst.molecule import Molecule
from diffpy.srreal.pdfcalculator import ConstantPeakWidth
from diffpy.srfit.pdf import PDFContribution
from diffpy.srfit.fitbase import FitRecipe, FitResults

nphcrystal = loadCrystal('naphthalene.cif')
nphmol = Molecule(nphcrystal, "naphthalene")
numatoms = nphcrystal.GetNbScatterer()
atoms = [nphcrystal.GetScatterer(i) for i in range(numatoms)]
xyzf = np.array([(a.X, a.Y, a.Z) for a in atoms])
xyzc = np.array(
    [nphcrystal.FractionalToOrthonormalCoords(x, y, z) for x, y, z in xyzf])
xyzcmol = xyzc - xyzc.mean(axis=0)

spC1 = nphcrystal.GetScatteringPower('C1')
for a, (xc, yc, zc) in zip(atoms, xyzcmol):
    nphmol.AddAtom(xc, yc, zc, spC1, a.GetName())
    nphcrystal.RemoveScatterer(a)
molposition = xyzf.mean(axis=0)
nphcrystal.AddScatterer(nphmol)
nphmol.X, nphmol.Y, nphmol.Z = xyzf.mean(axis=0)

pdfcntb = PDFContribution('pdfcntb')
pdfcntb.loadData('naphthalene.gr')
pdfcntb.qdamp = 0.06
pdfcntb.setCalculationRange(1.1, 25)
pdfcntb.addStructure('nphmol', nphmol, periodic=False)
import numpy as np
from scipy.optimize import leastsq

from pyobjcryst import loadCrystal
from pyobjcryst.molecule import Molecule
from diffpy.srreal.pdfcalculator import ConstantPeakWidth
from diffpy.srfit.pdf import PDFContribution
from diffpy.srfit.fitbase import FitRecipe, FitResults

nphcrystal = loadCrystal('naphthalene.cif')
nphmol = Molecule(nphcrystal, "naphthalene")
numatoms = nphcrystal.GetNbScatterer()
atoms = [nphcrystal.GetScatterer(i) for i in range(numatoms)]
xyzf = np.array([(a.X, a.Y, a.Z) for a in atoms])
xyzc = np.array([nphcrystal.FractionalToOrthonormalCoords(x, y, z)
                 for x, y, z in xyzf])
xyzcmol = xyzc - xyzc.mean(axis=0)

spC1 = nphcrystal.GetScatteringPower('C1')
for a, (xc, yc, zc)  in zip(atoms, xyzcmol):
    nphmol.AddAtom(xc, yc, zc, spC1, a.GetName())
    nphcrystal.RemoveScatterer(a)
molposition = xyzf.mean(axis=0)
nphcrystal.AddScatterer(nphmol)
nphmol.X, nphmol.Y, nphmol.Z = xyzf.mean(axis=0)

pdfcntb = PDFContribution('pdfcntb')
pdfcntb.loadData('naphthalene.gr')
pdfcntb.qdamp = 0.06
pdfcntb.setCalculationRange(1.1, 25)
pdfcntb.addStructure('nphmol', nphmol, periodic=False)