当前位置: 首页>>代码示例>>Python>>正文


Python Structure.volume方法代码示例

本文整理汇总了Python中structure.Structure.volume方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.volume方法的具体用法?Python Structure.volume怎么用?Python Structure.volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在structure.Structure的用法示例。


在下文中一共展示了Structure.volume方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PhysicalSystem

# 需要导入模块: from structure import Structure [as 别名]
# 或者: from structure.Structure import volume [as 别名]
class PhysicalSystem(Matter):

    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()
    #end def __init__


    def update_particles(self,clear=True):
        #add ions
        pc = dict()
        elem = list(self.structure.elem)
        for ion in set(elem):
            pc[ion] = elem.count(ion)
        #end for
        missing = set(pc.keys())-set(self.particles.keys())
        if len(missing)>0 or len(elem)==0:
            if clear:
                self.particles.clear()
            #end if
            self.add_particles(**pc)

            #pseudize
            if len(self.valency_in)>0:
                self.pseudize(**self.valency_in)
            #end if

            #add electrons
            self.generate_electrons(self.net_charge_in,self.net_spin_in)
        #end if
    #end def update_particles


    def update(self):
        self.net_charge = self.structure.background_charge
        self.net_spin   = 0
        for p in self.particles:
            self.net_charge += p.count*p.charge
            self.net_spin   += p.count*p.spin
        #end for
        self.net_charge = int(round(float(self.net_charge)))
        self.net_spin   = int(round(float(self.net_spin)))
    #end def update


    def add_particles(self,**particle_counts):
        pc = self.particle_collection # all known particles
        plist = []
        for name,count in particle_counts.iteritems():
            particle = pc.get_particle(name)
            if particle is None:
                self.error('particle {0} is unknown'.format(name))
            else:
                particle = particle.copy()
            #end if
            particle.set_count(count)
            plist.append(particle)
        #end for
        self.particles.add_particles(plist)
#.........这里部分代码省略.........
开发者ID:Paul-St-Young,项目名称:myNexus,代码行数:103,代码来源:physical_system.py

示例2: PhysicalSystem

# 需要导入模块: from structure import Structure [as 别名]
# 或者: from structure.Structure import volume [as 别名]

#.........这里部分代码省略.........
        #end if
    #end def change_units


    def group_atoms(self):
        self.structure.group_atoms()
        if self.folded_system!=None:
            self.folded_system.group_atoms()
        #end if
    #end def group_atoms


    def copy(self):
        cp = DevBase.copy(self)
        if self.folded_system!=None and self.structure.folded_structure!=None:
            del cp.folded_system.structure
            cp.folded_system.structure = cp.structure.folded_structure
        #end if
        return cp
    #end def copy


    def load(self,filepath):
        DevBase.load(self,filepath)
        if self.folded_system!=None and self.structure.folded_structure!=None:
            del self.folded_system.structure
            self.folded_system.structure = self.structure.folded_structure
        #end if
    #end def load


    def tile(self,*td,**kwargs):
        extensive = True
        if 'extensive' in kwargs:
            extensive = kwargs['extensive']
        #end if
        supercell = self.structure.tile(*td)
        if extensive:
            ncells = int(round(supercell.volume()/self.structure.volume()))
            net_charge = ncells*self.net_charge
            net_spin   = ncells*self.net_spin
        else:
            net_charge = self.net_charge
            net_spin   = self.net_spin
        #end if
        supersystem = PhysicalSystem(
            structure  = supercell,
            net_charge = net_charge,
            net_spin   = net_spin,
            **self.valency
            )
        return supersystem
    #end def tile


    def remove_folded_system(self):
        print 'removing folded system',self.folded_system.__class__.__name__
        self.folded_system = None
        self.structure.remove_folded_structure()
    #end def remove_folded_system


    def folded_representation(self,arg0,arg1=None):
        self.error('folded_representation needs a developers attention to make it equivalent with tile')
        if isinstance(arg0,PhysicalSystem):
            folded_system = arg0
        elif isinstance(arg0,str):
            shape = arg0
            tiling    = arg1
            if tiling is None:
                tiling = (1,1,1)
            #end if
            if not 'generation_info' in self:
                self.error('system was not formed with generate_physical_system, cannot form folded representation')
            #end if
            structure,element,scale,units,net_charge,net_spin,particles,valency = \
                self.generation_info.tuple('structure','element','scale','units', \
                                               'net_charge','net_spin','particles','valency')
            folded_system = generate_physical_system(
                structure  = structure,
                shape      = shape,
                element    = element,
                tiling     = tiling,
                scale      = scale,
                units      = units,
                net_charge = net_charge,
                net_spin   = net_spin,
                particles  = particles,
                **valency
                )
        else:
            self.error('unrecognized inputs in folded_representation')
        #end if
        tilematrix,kmap = self.structure.fold(folded_system.structure,'tilematrix','kmap')
        self.set(
            folded_system = folded_system,
            tilematrix    = tilematrix,
            kmap          = kmap
            )
        return folded_system
开发者ID:jyamu,项目名称:qmc,代码行数:104,代码来源:physical_system.py


注:本文中的structure.Structure.volume方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。