dump.data转cif脚本及打包exe

dump.data转cif脚本及打包exe

1 此工具只适合含有C H O Ca四种体系的
2 原始配置文件C定义类型为1 H定义类型为2 O定义类型为3
3 适用于导入Material Studio进行可视化操作。
用途:模拟用途~~关键词:Reaxff,Lammps,热解等~

dump2cif GUI脚本

ui_cif_support.py 模块 实现主要功能

#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 4.22
#  in conjunction with Tcl version 8.6
#    May 13, 2019 05:28:00 AM CST  platform: Windows NT

import sys
from tkinter import filedialog
from tkinter import messagebox
import re
import datetime
import pandas as pd
import os

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

def convert():
    input_aim = w.Entry1.get().strip()
    print(input_aim)
    with open(file_path, 'r') as f:
        rows = f.read() + 'ITEM: TIMESTEP'
        rule = 'ITEM: TIMESTEP\n{}.*?(?=ITEM: TIMESTEP)'.format(input_aim)
        aim_text_list = re.search(rule, rows, re.S)
        aim_text_string = aim_text_list.group()
    f_aim_text = open('aim_middle.atom', 'w')
    f_aim_text.write(aim_text_string)
    f_aim_text.close()
    print('以获取目标数据块...')

    raw_cif = open('{}.cif'.format(input_aim), 'w')
    time = datetime.datetime.now().strftime('%Y-%m-%d')
    aim_date_block = aim_text_string
    global start
    start = datetime.datetime.now()
    # print(type(aim_date_block))
    data = aim_date_block.split('\n')
    # print(data)
    boxsize = []
    for index, row in enumerate(data):
        if row.startswith('ITEM: BOX BOUNDS'):
            boxsize.append(data[index + 1].split())
            boxsize.append(data[index + 2].split())
            boxsize.append(data[index + 3].split())
    # print(boxsize)
    box_long = float(boxsize[0][1]) - float(boxsize[0][0])
    box_weight = float(boxsize[1][1]) - float(boxsize[1][0])
    box_height = float(boxsize[2][1]) - float(boxsize[2][0])
    print('计算盒子尺寸成功...', box_long, box_weight, box_height)
    header_text = '''data_reax2ms
_audit_creation_date    {}
_audit_creation_method  'Materials Studio'
_symmetry_space_group_name_H-M  'P1'
_symmetry_Int_Tables_number 1
_symmetry_cell_setting  triclinic
loop_
_symmetry_equiv_pos_as_xyz
  x,y,z
_cell_length_a  {}
_cell_length_b  {}
_cell_length_c  {}
_cell_angle_alpha   90.0000
_cell_angle_beta    90.0000
_cell_angle_gamma   90.0000
loop_
_atom_site_label
_atom_site_type_symbol
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_U_iso_or_equiv
_atom_site_adp_type
_atom_site_occupancy'''.format(time, box_long, box_weight, box_height)

    raw_cif.write(header_text)
    raw_cif.close()
    print('初始化cif成功...')

    with open('aim_middle.atom', 'r') as f:
        data_string = f.read()
        newdata_string = re.findall('id.*type.*', data_string, re.S)
        # print(newdata_string[0])

    f2 = open('out2pandas.txt', 'w')
    f2.write(newdata_string[0])
    f2.close()

    sheet = pd.read_csv('out2pandas.txt', sep=' ', engine='python')
    df = sheet.dropna(axis=1)
    df['type'] = df['type'].apply(

ui_cif.py主要是GUI代码,由Page生成,个人觉得没必要花时间去研究一个tkinter的库,有造好的轮子直接用就是。有个tkinter-designer 搭配VB6.0也能很快构建一些简单的图形界面。

#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.22
#  in conjunction with Tcl version 8.6
#    May 13, 2019 05:27:55 AM CST  platform: Windows NT

import sys
from tkinter import filedialog
try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import ui_cif_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    top = Toplevel1 (root)
    ui_cif_support.init(root, top)
    root.mainloop()

w = None
def create_Toplevel1(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = tk.Toplevel (root)
    top = Toplevel1 (w)
    ui_cif_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Toplevel1():
    global w
    w.destroy()
    w = None

class Toplevel1:
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85'
        _ana2color = '#ececec' # Closest X11 color: 'gray92'

        top.geometry("567x294+263+290")
        top.title("dump2cif--Author:Huangkai 360hkhk@gmail.com")
        top.configure(background="#d9d9d9")

        self.Entry1 = tk.Entry(top)
        self.Entry1.place(relx=0.547, rely=0.34,height=41, relwidth=0.219)
        self.Entry1.configure(background="white")
        self.Entry1.configure(disabledforeground="#a3a3a3")
        self.Entry1.configure(font="TkFixedFont")
        self.Entry1.configure(foreground="#000000")
        self.Entry1.configure(insertbackground="black")
        self.Entry1.configure(width=124)

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.176, rely=0.374, height=26, width=188)
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(text='''2 Please input a timestep''')

        self.Button1 = tk.Button(top)
        self.Button1.place(relx=0.6, rely=0.136, height=33, width=73)
        self.Button1.configure(activebackground="#ececec")
        self.Button1.configure(activeforeground="#000000")
        self.Button1.configure(background="#d9d9d9")
        self.Button1.configure(command=ui_cif_support.openfile)
        self.Button1.configure(disabledforeground="#a3a3a3")
        self.Button1.configure(foreground="#000000")
        self.Button1.configure(highlightbackground="#d9d9d9")
        self.Button1.configure(highlightcolor="black")
        self.Button1.configure(pady="0")
        self.Button1.configure(text='''Browser''')

        self.Label2 = tk.Label(top)
        self.Label2.place(relx=0.176, rely=0.136, height=26, width=196)
        self.Label2.configure(background="#d9d9d9")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(foreground="#000000")
        self.Label2.configure(text='''1 Please select your dump''')

        self.Button2 = tk.Button(top)
        self.Button2.place(relx=0.265, rely=0.612, height=33, width=72)
        self.Button2.configure(activebackground="#ececec")
        self.Button2.configure(activeforeground="#000000")

脚本截图:

exe打包地址:链接: https://pan.baidu.com/s/1QjFSbDJNh4EJrayZGoni4g 提取码: 8685

Last modification:May 14th, 2019 at 05:42 pm

Leave a Comment