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


Python Model.add方法代码示例

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


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

示例1: testModel

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]
def testModel():
    model = Model()
    model.add(Dense(
        outputShape=(3, 3,),
        inputShape=(3, 2,)
    ))
    model.add(Activation('sigmoid'))

    model.compile()

    result = model.objectiveFunction([[6, 1], [7, 2], [8, 3]], [[7, 6, 2], [1, 2, 3], [4, 0, 5]])

    print(result)
开发者ID:fyabc,项目名称:MSRAPaperProject,代码行数:15,代码来源:tests.py

示例2: main

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]
def main():
    # sys.argv == [categorize_parameters.txt, modelfile]
    if len(sys.argv) <= 2:
        sys.exit(
            "\nERROR! Fix your inputs!\n\nArg 1:  input param file detailing each voronoi 'structure'.\nShould be of the form:\nCrystal:\n    0,2,8,*\n\nArg2: a model file.\n\nOutput is printed to screen."
        )

    paramfile = sys.argv[1]
    modelfiles = sys.argv[2:]

    from cutoff import cutoff

    vp_dict = load_param_file(paramfile)

    m0 = Model(modelfiles[0])
    m0.generate_neighbors(cutoff)
    # voronoi_3d(m0, cutoff)
    # set_atom_vp_types(m0, vp_dict)
    # stats0 = VPStatistics(m0)
    # stats0.print_indexes()
    # stats0.print_categories()

    from atom import Atom

    m = Model(
        "atoms with less than 12 neighbors in Zr50Cu45Al15 MD model (originally with 91200 atoms)",
        m0.lx,
        m0.ly,
        m0.lz,
        [],
    )
    count = 0
    for j, atom in enumerate(m0.atoms):
        if len(atom.neighs) >= 12:
            continue
        new = Atom(count, "Si", *atom.coord)
        count += 1
        print("Added new atom {0}".format(new))
        m.add(new)
    m.write("less_than_12_neighbors.xyz")

    if len(modelfiles) > 1:
        for modelfile in modelfiles[1:]:
            m = Model(modelfile)
            voronoi_3d(m, cutoff)
            set_atom_vp_types(m, vp_dict)

            stats0 = stats0 + m
            stats0.print_categories()
            stats0.print_indexes()
开发者ID:adehgha,项目名称:model_analysis,代码行数:52,代码来源:categorize_vor.py

示例3: combine

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]
    def combine(self, colorize=True, force_update=False):
        """ Combines the group of aligned clusters into a single model. """
        if not force_update and self._combined is not None:
            return self._combined

        m = Model(comment='combined structures', xsize=100.,ysize=100.,zsize=100., atoms=[])
        count = 0
        atom_types = ['Si', 'Na', 'Mg', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'B', 'Al', 'Ga', 'C', 'Sn', 'Pb', 'O']
        for i,cluster in enumerate(self.clusters):
            if not cluster.successful: continue
            for j,atom in enumerate(cluster.aligned_target):
                if j == len(cluster.aligned_target.atoms): break
                if colorize:
                    new = Atom(count, atom_types[j], *atom.coord)
                else:
                    new = Atom(count, 'Si', *atom.coord)
                count += 1
                m.add(new)
        self._combined = m
        return m
开发者ID:jjmaldonis,项目名称:model_analysis,代码行数:22,代码来源:rotation_alignment_analysis.py

示例4: test_add

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]
    def test_add(self):
        model = Model()
        self.assertEqual(len(model.lines), 0)
        self.assertEqual(model.add(''), False)
        self.assertEqual(len(model.lines), 0)
        self.assertEqual(model.add('   '), False)
        self.assertEqual(len(model.lines), 0)
        self.assertEqual(model.add(' a =  b  '), True)
        self.assertEqual(len(model.lines), 1)
        self.assertEqual(model.lines[0].text, 'a = b')
        self.assertEqual(model.lines[0].context, {})
        self.assertEqual(model.add('   a   = b'), False)
        # the second time the model does not add the same item

        self.assertEqual(len(model.lines), 1)
        self.assertEqual(model.add(' c d  ', {'date': '-'}), True)
        self.assertEqual(len(model.lines), 2)
        self.assertEqual(model.lines[1].text, 'c d')
        self.assertEqual(model.lines[1].context, {'date': '-'})
        self.assertEqual(model.add(' e  ', {'test': '0'}), True)
        self.assertEqual(len(model.lines), 3)
        self.assertEqual(model.lines[2].text, 'e')
        self.assertEqual(model.lines[2].context,
                         {'date': '-', 'test': '0'})
开发者ID:alexandre-solovyov,项目名称:lang,代码行数:26,代码来源:test_model.py

示例5: main

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]

#.........这里部分代码省略.........
        print(cn)

    return 0

    modelfile = sys.argv[2]
    m = Model(modelfile)
    xtal_atoms = sys.argv[3]
    xtal_atoms = Model(xtal_atoms).atoms

    #x,y,z = (round(x,6) for x in self.coord)
    #a,b,c = (round(x,6) for x in other.coord)
    #print("HERE")
    #print([round(x,7) for x in xtal_atoms[13].coord])
    #print([round(x,7) for x in m.atoms[153].coord])
    #print(type(xtal_atoms[13]))
    #print(type(m.atoms[153]))
    #print(xtal_atoms[13] == m.atoms[153])
    #return 0

    glassy_atoms = []
    for atom in m.atoms:
        if atom not in xtal_atoms:
            glassy_atoms.append(atom)
    print(len(glassy_atoms))
    print(len(xtal_atoms))
    assert len(glassy_atoms) + len(xtal_atoms) == m.natoms
    voronoi_3d(m, cutoff)
    set_atom_vp_types(m, vp_dict)
    m.generate_neighbors(3.45)
    head, tail = os.path.split(modelfile)
    head = head + '/'
    if not os.path.exists(head+'glassy/'):
        os.makedirs(head+'glassy/')
    if not os.path.exists(head+'xtal/'):
        os.makedirs(head+'xtal/')
    for count, atom in enumerate(xtal_atoms):
        i = m.atoms.index(atom)
        atom = m.atoms[i]
        new = Model('{0}'.format(atom.vp.index), m.lx, m.ly, m.lz, atom.neighs + [atom])
        fix_cluster_pbcs(new)
        val = normalize_bond_distances(new)
        new.comment = '{0}; bond length scaling factor is {1}'.format(atom.vp.index, val)
        center = find_center_atom(new)
        new.remove(center)
        new.add(center)
        vp_str = ''.join([str(x) for x in atom.vp.index])
        new.write(head+'xtal/{0}.xyz'.format(count))
    for count, atom in enumerate(glassy_atoms):
        i = m.atoms.index(atom)
        atom = m.atoms[i]
        new = Model('{0}'.format(atom.vp.index), m.lx, m.ly, m.lz, atom.neighs + [atom])
        fix_cluster_pbcs(new)
        val = normalize_bond_distances(new)
        new.comment = '{0}; bond length scaling factor is {1}'.format(atom.vp.index, val)
        center = find_center_atom(new)
        new.remove(center)
        new.add(center)
        vp_str = ''.join([str(x) for x in atom.vp.index])
        new.write(head+'glassy/{0}.xyz'.format(count))
    return 0
        




    for atom in volume_atoms.atoms:
        for i,atom2 in enumerate(m.atoms):
            if(atom.z == atom2.z and [round(x, 5) for x in atom.coord] == [round(x, 5) for x in atom2.coord]): good[i] = True
    count = defaultdict(int) # Stores how many VPs have been found of each index type
    for modelfile in modelfiles:
        print(modelfile)
        m = Model(modelfile)
        voronoi_3d(m,cutoff)
        set_atom_vp_types(m,vp_dict)
        #vor_stats(m)
        #cats = index_stats(m)
        for i,atom in enumerate(m.atoms):
            if not good[i]: continue
            #new = Model('0,0,12,0; number of atoms is {0};'.format(count), m.lx, m.ly, m.lz, atom.neighs + [atom])
            new = Model('{0}; number of atoms is {1};'.format(atom.vp.index, count), m.lx, m.ly, m.lz, atom.neighs + [atom])
            fix_cluster_pbcs(new)
            val = normalize_bond_distances(new)
            new.comment = '{0}; number of atoms is {1}; bond length scaling factor is {2}'.format(atom.vp.index, count,val)
            center = find_center_atom(new)
            new.remove(center)
            new.add(center)
            vp_str = ''.join([str(x) for x in atom.vp.index])
            if not os.path.exists(vp_str):
                os.makedirs(vp_str)
            new.write('{0}/{0}.{1}.xyz'.format(vp_str, count[atom.vp.index]))
            count[atom.vp.index] += 1
        print(count)
        for c,v in count.items():
            print("{0}: {1}".format(c,v))
        print(sum(count.values()))
        cn = 0.0
        for atom in m.atoms:
            cn += atom.cn
        cn = float(cn)/m.natoms
        print(cn)
开发者ID:adehgha,项目名称:model_analysis,代码行数:104,代码来源:generate_VP_clusters.py

示例6: main

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import add [as 别名]
def main():
    # Load the MD model
    modelfile = sys.argv[1]
    md = Model(modelfile)

    # Make a model to hold all the atoms we pull out to make sure the original model was sampled uniformly.
    # Only the center atoms are added to this model.
    holding_model = Model(comment='holding box', xsize=md.xsize, ysize=md.ysize, zsize=md.zsize, atoms=[])

    # Load the cutoff dictionary so that we can generate neighbors for every atom
    from cutoff import cutoff

    # Directory name to save the files to
    dir = 'all_91200_clusters'
    if not os.path.exists(dir):
        os.makedirs(dir)

    # Set the number of clusters to randomly select
    num_clusters = 'all'
    if num_clusters == 'all' or num_clusters == md.natoms:
        random_selection = False
        num_clusters = md.natoms
    else:
        num_clusters = min(num_clusters, md.natoms)
        random_selection = True

    if random_selection:
        unpicked = range(md.natoms)

    start = 0
    for n in range(start, num_clusters+start):
        if random_selection:
            rand = random.choice(unpicked)
            unpicked.remove(rand)
            atom = md.atoms[rand]
        else:
            atom = md.atoms[n-start]
            rand = n-start

        # Generate neighbors for this atom
        atom.neighs = md.get_atoms_in_cutoff(atom, cutoff)
        if(atom in atom.neighs): atom.neighs.remove(atom)
        atom.cn = len(atom.neighs)

        holding_model.add(atom)

        # Create the cluster, normalize the bond distances, and write to disk
        atoms = atom.neighs + [atom]
        # c = create_cluster(md, atom, start, n, rand, center_included=True)
        c = Cluster(
            comment='cluster #{0} from atom {1}'.format(n-start, rand),
            xsize=md.xsize,
            ysize=md.ysize,
            zsize=md.zsize,
            atoms=atoms,
            center_included = True
        )
        ratio = c.normalize_bond_distances()
        c.comment='cluster #{0} from atom {1}; normalized bond distances by {2}'.format(n-start, rand, ratio)
        c.write(os.path.join(dir, '{0}.xyz'.format(n)))
        print(n-start, atom.id)
        #print(c)

    holding_model.write(os.path.join(dir, 'holding_model.xyz'))
开发者ID:jjmaldonis,项目名称:model_analysis,代码行数:66,代码来源:generate_clusters_for_alignment.py


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