# Internal
from cdi import (Schema, Entity, Attr, FK, Int, Decimal, Double, Varchar, Text,
                 Date, PathEQ, Path, JLit, String, Gen, Boolean, EQ)

from ..inputs.javafuncs import gteq
################################################################################
#############
# Catalysis #
#############

job = Entity(name='job',
             desc='DFT job',
             attrs=[
                 Attr('stordir',
                      Varchar,
                      desc='Directory containing log file',
                      id=True),
                 Attr('job_name', Varchar, desc='Name of job - arbitrary'),
                 Attr('user', Varchar, desc='Owner of job'),
                 Attr('energy', Double, desc='Energy result of job')
             ],
             fks=[FK('struct'), FK('calc')])

elem = Entity(name='element',
              desc='chemical element',
              attrs=[
                  Attr('atomic_number', desc='# of protons', id=True),
                  Attr('symbol', Varchar, desc='E.g. He, K, Li'),
                  Attr('name', Varchar)
              ])
            # Compute the L² Norm of three 3D vectors
       ] + [SQLAttr(structs,abc,Double,
                    Sum([structs['%s%d'%(xyz,i)] ** Literal(2)
                          for i in range(1,4)]) ** Literal(0.5))
            for abc,xyz in zip('abc','xyz')

       ] + [SQLAttr(calcs,attr,Varchar,Literal(constval))
            for attr,constval in calc_constants.items()],

    # 1.4: Attrs computed in CQL (can use Java functions + info from multiple tables)
    #---------------------------------------------------------------------------
    new_attr1 = [NewAttr(structs,'composition',  String, mcd(structs['comp'])),
                 NewAttr(structs,'raw',          Text,   msj(*msj_args)),
                 NewAttr(atoms,'ind',Int,bigint_to_int(atoms['bigind']))],

    # 1.5: New Entities computed in CQL
    #----------------------------------
    new_ent1  = [NewEntity(name  = 'struct_composition',
                           gens  = [s0, l0],
                           where = [EQ(gt(elemcount, zero) , JLit('true',Boolean))],
                           attrs = {Attr('num',Int) : elemcount},
                           fks   = {FK('struct','structures') : s0,
                                    FK('element','elements')  : l0}),

                NewEntity(name = 'bulk',
                          gens = [s0],
                          fks  = {FK('struct','structures') : s0})]

                  )
Exemple #3
0
# External
from typing import Dict as D

# Internal
from cdi import (Schema, Entity, Attr, FK, Int, Tinyint, Double, Varchar, Text,
                 Date, PathEQ, Path, flatten, Zero, IN, Literal as Lit, LT,
                 SQLExpr)

################################################################################

journals = Entity(name='journals',
                  id='id',
                  attrs=[Attr('code', Varchar, id=True),
                         Attr('name', Text)])

authors = Entity(
    name='authors',
    id='id',
    attrs=[Attr('last', Varchar, id=True),
           Attr('first', Varchar, id=True)])

rots = Entity(name='rotations',
              id='id',
              attrs=[
                  Attr('a%d%d' % (i, j), Double, id=True) for i in range(3)
                  for j in range(3)
              ])

trans = Entity(name='translations',
               id='id',
               attrs=[Attr(x, Double, id=True) for x in 'xyz'])
Exemple #4
0
# External
from typing import Callable as C
# Internal
from cdi import Schema, Entity, Attr, Varchar, FK, Instance, Gen, JLit, Integer
################################################################################
Chap = Entity(name='Chap',
              desc="A chapter within a book",
              id='id',
              attrs=[
                  Attr('num', id=True, desc='Chapter #'),
                  Attr('text', Varchar, desc='Full text of a chapter')
              ],
              fks=[FK('novel_id', 'Nov', id=True)])

Nov = Entity(name='Nov',
             desc='A book',
             id='id',
             attrs=[
                 Attr('aname', Varchar, desc='Author name'),
                 Attr('title', Varchar, id=True, desc='Book title '),
                 Attr('year', desc='Book publish date')
             ])

Readr = Entity(
    name='Readr',
    desc='A reader',
    id='id',
    attrs=[
        Attr('rname', Varchar, desc='Reader name'),
        Attr('borrowed',
             Varchar,
Exemple #5
0
    new_attr1=[
        NewAttr(Chap, 'n_words', Integer, count_words(chap['text'])),
    ],
    new_fk1=[NewFK(Nov, FK('wrote', 'Author'), nov)],
    new_ent1=[
        NewEntity(name='Author', gens=[nov]),
        NewEntity(name='Borrow',
                  gens=[nov, readr],
                  where=[
                      EQ(
                          matches(readr['borrowed'],
                                  concat(wild, nov['title'], wild)),
                          Lit('true', Boolean))
                  ],
                  attrs={
                      Attr('total_len', Integer):
                      plus(Len(readr['rname']), Len(nov['title']))
                  },
                  fks={
                      FK('r', 'Readr'): readr,
                      FK('n', 'Nov'): nov
                  })
    ],
)

if __name__ == '__main__':
    m = Migrate(src=src, tar=tar, overlap=overlap, funcs=funcs)
    fi = m.file(src=isrc, tar=itar, merged=Conn(db='lib_merged'))
    with open('cdi/library_example/lib.cql', 'w') as f:
        f.write(fi)