用Python写lammps data文件

B站视频


import numpy as np

# Number of atoms to create

natoms = 1000

# Size of the system cell in Angstroms

# Assuming a cubic cell

system_size = 20.0

# Generate atom postitions

# Random for amorphous glass

positions    =    []

for    i    in    range(natoms):

    positions.append(np.random.rand(3)*system_size)

# Write Lammps data file

with open(‘random.data’ ,’w’) as fdata:

     # First line is a comment line

    fdata.write( ‘Random atoms\n\n’)

    # Header 

    # Specify number of atoms and atom types

    fdata.write( ‘{} atoms\n’.format(natoms)

    fdata.write( ‘{} atom types\n’.format(1))

    # Specify box dimensions

    fdata.write( ‘{} {} xlo xhi\n’.format(0.0, system_size)   
    fdata.write( ‘{} {} ylo yhi\n’.format(0.0, system_size))
    fdata.write( ‘{} {} zlo zhi\n’.format(0.0, system_size))

    fdata.write(‘\n’)

    #Atoms sections

    fdata.write(‘Atoms\n\n’)

    # Write each positions 与原子类型有关(full atomic等)

    for i,pos in enumerate(positions):
        fdata.write(‘{} 1 {} {}\n’.format(i+1, *pos))

    # If you have bonds and angles, further sections below

https://www.jianshu.com/p/8dab852c0b24

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论