surf = Entity(name='surface', desc='Subset of struct: periodicity in 1 or 2 dimensions', attrs=[ Attr('facet', Varchar, desc="Autodetected facet"), Attr('vacuum', Decimal, desc='Layer separation (Angstrom)') ], fks=[FK('struct', id=True)]) rich_objs = [ job, elem, species, struct, cell, atom, calc, struct_comp, bulk, mol, surf ] ################################################################################ # Path Equations ################ b0, m0, s0 = Gen('b0', bulk), Gen('m0', mol), Gen('s0', surf) st0, a0 = Gen('st0', struct), Gen('a0', atom) rich_pe = [ PathEQ(Path(atom['number']), Path(atom['element'], elem['atomic_number'])), PathEQ(Path(b0['struct'], struct['system_type']), Path(JLit('bulk', String))), PathEQ(Path(m0['struct'], struct['system_type']), Path(JLit('molecule', String))), PathEQ(Path(s0['struct'], struct['system_type']), Path(JLit('surface', String))), PathEQ(Path(st0['species'], species['phase']), Path(st0['system_type'])), PathEQ(Path(gteq(a0['x'], JLit("0.000", Double))), Path(JLit('true', Boolean))) ]
Readr = Entity( name='Readr', desc='A reader', id='id', attrs=[ Attr('rname', Varchar, desc='Reader name'), Attr('borrowed', Varchar, desc= 'Comma separated list of books reader has checked out of library') ], fks=[FK('fav', 'Nov')]) src = Schema('src', [Chap, Nov, Readr]) r1, r2 = [Gen('r%d' % i, Readr) for i in range(1, 3)] n1, n2, n3 = [Gen('n%d' % i, Nov) for i in range(1, 4)] n1c1, n1c2, n2c1, n3c1 = [ Gen('n%dc%d' % (x, y), Chap) for x, y in [(1, 1), (1, 2), (2, 1), (3, 1)] ] one, two, y1, y2, y3 = [JLit(x, Integer) for x in [1, 2, 1924, 1915, 1926]] # Wrap Python string as a typed Java string s = lambda x: JLit(x, Varchar) # type: C[[str],JLit] isrc = Instance({ Readr['fav']: { r1: n1, r2: n2 }, Chap['novel_id']: {
where='structure_id = structures.id') atoms_ind = atoms['id'] - SUBSELECT( MIN(atoms['id']), tab='atoms A', where='A.structure_id=atoms.structure_id') xs, ys, zs = [ SUBSELECT(GROUP_CONCAT(atoms[x]), tab='atoms', where='structure_id = structures.id') for x in 'xyz' ] calc_constants = dict(dftcode='vasp', xc='PBE', user='******') # Generators for CQL expressions #------------------------------- s0 = Gen('s0', structs) l0 = Gen('e0', elems) # Helpers for CQL expressions #--------------------------- zero = JLit('0', Int) # java literal elemcount = countsubstr(s0['comp'], cat(l0['symbol'], JLit(',', String))) msj_kwargs = ['comp', 'xs', 'ys', 'zs'] + [a + b for a in 'xyz' for b in '123'] msj_args = [structs[x] for x in msj_kwargs] ####################################### # Section 1: Specification of overlap # #######################################
count_words = JavaFunc( 'count_words', [String], Integer, "return 1 + input[0].length() - input[0].replaceAll(' ', '').length()") Len = JavaFunc('len', [String], Integer, "return input[0].length()") plus = JavaFunc('plus', [Integer, Integer], Integer, "return input[0] + input[1]") matches = JavaFunc('matches', [String, String], Boolean, "return input[0].matches(input[1])") cat = JavaFunc('cat', [String, String], String, "return input[0] + input[1]") funcs = [count_words, Len, plus, matches, cat] ######################################################################## # Map any relevant objs/attrs/relations in source onto paths in target # ######################################################################## chap, nov, readr = Gen('Chap', Chap), Gen('Nov', Nov), Gen('Readr', Readr) overlap = Overlap( s1=src, s2=tar, paths=[ PathEQ(Path(Nov['title']), Path(Novel['title'])), PathEQ(Path(Nov['aname']), Path(Novel['wrote'], Author['authorname'])), PathEQ(Path(Chap['num']), Path(Chapter['num'])), PathEQ(Path(Chap['novel_id']), Path(Chapter['novel'])), PathEQ(Path(Readr['rname']), Path(Reader['readername'])), PathEQ(Path(Readr['fav']), Path(Reader['favorite'])) ], new_attr1=[ NewAttr(Chap, 'n_words', Integer, count_words(chap['text'])), ],