本文整理汇总了Python中structure.Structure类的典型用法代码示例。如果您正苦于以下问题:Python Structure类的具体用法?Python Structure怎么用?Python Structure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Structure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fromString
def fromString(self, data):
Structure.fromString(self,data)
# Parse the ctx_items
data = self['ctx_items']
for i in range(self['ctx_num']):
item = CtxItemResult(data)
self.__ctx_items.append(item)
data = data[len(item):]
示例2: __init__
def __init__(self, data = None, alignment = 0):
self.__ctx_items = []
Structure.__init__(self,data,alignment)
if data is None:
self['Pad'] = ''
self['ctx_items'] = ''
self['sec_trailer'] = ''
self['auth_data'] = ''
示例3: _get_fk_data
def _get_fk_data(self, table_name, fk, fk_value):
reltable = Structure.get_fk_referenced_table(table_name, fk)
reltable_pk = Structure.get_primary_key(reltable)
if not self._cache.relation_exists(table_name, reltable):
sql = SQLBuilder(reltable)
sql.add_where_literal(Column(reltable, reltable_pk).in_(self._cache.get_all_keys(table_name, fk)))
data = Query().execute_and_fetch(**sql.build_select())
self._cache.save_relation(table_name, reltable, data)
return Row(self._cache.get_relation_row(reltable, reltable_pk, fk_value), reltable, self)
示例4: _get_rel_data_restricted
def _get_rel_data_restricted(self, sql):
attr, pk = self._restricted_table_attr, self._get_pk()
relation_fk = Structure.get_foreign_key_for_table(attr, self._table_name)
sql.add_where_condition(relation_fk, self.data[pk])
data = Query().execute_and_fetch(**sql.build_select())
from resultset import ResultSet
return ResultSet(data, attr)
示例5: _get_rel_data_restricted
def _get_rel_data_restricted(self, sql):
saved = self._restricted_table_call
table_name, relation, pk, pk_value = saved['table_name'], saved['relation'], saved['pk'], saved['pk_value']
relation_fk = Structure.get_foreign_key_for_table(relation, table_name)
if not self._cache.relation_exists(table_name, relation):
if sql._select_args:
sql.add_select_arg(Column(relation, relation_fk))
if sql._limit:
union_sql = []
union_parameters = []
union_dict = {}
for id in self._cache.get_all_keys(table_name, pk):
limiting_sql = copy.deepcopy(sql)
limiting_sql.add_where_literal(Column(relation, relation_fk) == id)
union_dict = limiting_sql.build_select()
union_sql.append('(%s)' % union_dict['sql'])
union_parameters.extend(union_dict['parameters'])
union_dict['sql'], union_dict['parameters'] = ' UNION '.join(union_sql), union_parameters
data = Query().execute_and_fetch(**union_dict)
self._cache.save_relation(table_name, relation, data)
else:
sql.add_where_literal(Column(relation, relation_fk).in_(self._cache.get_all_keys(table_name, pk)))
data = Query().execute_and_fetch(**sql.build_select())
self._cache.save_relation(table_name, relation, data)
return ResultSet(self._cache.get_relation_set(relation, relation_fk, pk_value), relation, self._cache)
示例6: select
def select(self, *args):
if args:
map(lambda arg: self._check_is_instance(arg, 'Column'), args)
args = list(args)
args.append(Column(self._table_name, Structure.get_primary_key(self._table_name)))
self._sql.add_select_args(args)
return self._table_selected_instance()
示例7: __init__
def __init__(self, url):
"""Construct a new Firebase reference from a full Firebase URL."""
self.connection = Connection(url, self)
self.base_url = url
self.structure = Structure(self)
self.subscriptions = {}
self.history = []
self.connection.daemon = True
self.connection.start()
atexit.register(self.close)
DataRef.__init__(self, self, "")
示例8: make_movie
def make_movie(self,filename,filepath=None):
if 'structures' in self:
from structure import Structure
if filepath==None:
filepath = os.path.join(self.abspath,filename)
else:
filepath = os.path.join(filepath,filename)
#end if
movie = ''
structures = self.structures
aA = convert(self.input.system['celldm(1)'],'B','A')
cell = self.input.cell_parameters.vectors
for i in range(len(structures)):
s = structures[i]
struct = Structure(elem=s.atoms,pos=s.positions,axes=cell,scale=aA,units='A')
struct=struct.tile(2,2,2)
ss=struct.write_xyz()
movie += ss
open(filepath,'w').write(movie)
示例9: __getattr__
def __getattr__(self, attr):
self._check_deleted()
if Structure.is_foreign_key(self._table_name, attr):
if self._result_set:
return self._result_set._get_fk_data(self._table_name, attr, self.data[attr])
else:
reltable = Structure.get_fk_referenced_table(self._table_name, attr)
reltable_pk = Structure.get_primary_key(reltable)
sql = SQLBuilder(reltable)
sql.add_where_condition(reltable_pk, self.data[attr])
data = Query().execute_and_fetch(**sql.build_select())
return Row(data[0], reltable)
else:
self._check_relation_exists(attr)
pk = self._get_pk()
if self._result_set:
return self._result_set._get_rel_data(self._table_name, attr, pk, self.data[pk])
else:
self._restricted_table_attr = attr
from restricted import RestrictedTableSelect
return RestrictedTableSelect(attr, SQLBuilder(attr), self)
示例10: __init__
def __init__(self, url, ssl_options=None):
'''Construct a new Firebase reference from a full Firebase URL.'''
self.connection = Connection(url, self, ssl_options=ssl_options)
self.base_url = url
self.structure = Structure(self)
self.subscriptions = {}
self.history = []
self.connection.daemon = True
self.connection.start()
self._keep_alive()
atexit.register(self.close)
DataRef.__init__(self, self, '')
示例11: __init__
def __init__(self,structure=None,net_charge=0,net_spin=0,particles=None,**valency):
self.pseudized = False
if structure is None:
self.structure = Structure()
else:
self.structure = structure
#end if
if particles is None:
self.particles = Particles()
else:
self.particles = particles.copy()
#end if
self.folded_system = None
if self.structure.folded_structure!=None:
vratio = structure.volume()/structure.folded_structure.volume()
ncells = int(round(vratio))
if abs(vratio-ncells)>1e-4:
self.error('volume of system does not divide evenly into folded system')
#end if
if net_charge%ncells!=0:
self.error('net charge of system does not divide evenly into folded system')
#end if
if net_spin%ncells!=0:
self.error('net_spin of system does not divide evenly into folded system')
#end if
self.folded_system = PhysicalSystem(
structure = structure.folded_structure,
net_charge = net_charge/ncells,
net_spin = net_spin/ncells,
particles = particles,
**valency
)
#end if
self.valency_in = obj(**valency)
self.net_charge_in = net_charge
self.net_spin_in = net_spin
self.update_particles(clear=False)
self.check_folded_system()
示例12: __init__
def __init__(self,structure=None,net_charge=0,net_spin=0,particles=None,**valency):
self.structure = structure
self.particles = particles
if structure==None:
self.structure = Structure()
#end if
if particles==None:
self.particles = Particles()
#end if
self.folded_system = None
if self.structure.folded_structure!=None:
self.folded_system = PhysicalSystem(
structure = structure.folded_structure,
net_charge = net_charge,
net_spin = net_spin,
particles = particles,
**valency
)
#end if
#add ions
pc = dict()
elem = list(self.structure.elem)
for ion in set(elem):
pc[ion] = elem.count(ion)
#end for
self.add_particles(**pc)
#pseudize
if len(valency)>0:
self.pseudize(**valency)
#end if
#add electrons
self.generate_electrons(net_charge,net_spin)
self.check_folded_system()
示例13: get_result
def get_result(self, result_name, sim):
result = obj()
input = self.input
if result_name == "structure":
# OUTCAR structure is not as precise as CONTCAR structure
# pa = self.load_analyzer_image()
# elem = input.poscar.elem
# elem_count = input.poscar.elem_count
# atoms = []
# for i in range(len(elem)):
# atoms += elem_count[i]*[elem[i]]
##end for
# structure = Structure(
# units = 'A',
# axes = pa.lattice_vectors.copy(),
# elem = atoms,
# pos = pa.position.copy()
# )
# get structure from CONTCAR
ccfile = os.path.join(self.locdir, self.identifier + ".CONTCAR")
if not os.path.exists(ccfile):
self.error("CONTCAR file does not exist for relax simulation at " + self.locdir)
# end if
contcar = Poscar(ccfile)
structure = Structure()
if contcar.elem != None:
structure.read_poscar(ccfile)
else:
elem, elem_count = self.system.structure.order_by_species()
structure.read_poscar(ccfile, elem=elem)
# end if
if input.poscar.dynamic != None:
structure.freeze(input.poscar.dynamic, negate=True)
# end if
result.structure = structure
else:
self.error("ability to get result " + result_name + " has not been implemented")
# end if
return result
示例14: join
def join(self, table, on=None):
self._check_is_instance(table, 'Table')
if on:
self._check_is_instance(on, 'Literal')
self._validate_on(table, on)
else:
Structure.tables_related(self._table_name, table._table_name)
try:
fk = Structure.get_foreign_key_for_table(self._table_name, table._table_name)
except PyPgException:
fk = Structure.get_foreign_key_for_table(table._table_name, self._table_name)
on = Column(table._table_name, fk) == \
Column(self._table_name, Structure.get_primary_key(self._table_name))
else:
on = Column(self._table_name, fk) == \
Column(table._table_name, Structure.get_primary_key(table._table_name))
self._sql.add_join(table._table_name, on)
return self._table_select_instance()
示例15: _check_relation_exists
def _check_relation_exists(self, relation):
Structure.table_exists(relation)
Structure.tables_related(relation, self._table_name)