2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OCTAのシミュレーション条件をファイルから取得してpandasで保存する

Last updated at Posted at 2020-04-07

##シミュレーションの条件をCSVファイルで保存する方法

OCTAを使用していると、どうしても設定をリスト化して保存したくなります。
毎回gourmetを起動して見るのが手間になるので、一部の設定をCSVファイルで保存できるようにしました。
単純なやり方です。条件を変数にいれて、それをPandasでシリーズにして、シリーズをデータフレームにした後、保存しています。

UDFManagerこのモジュールをimportすると、OCTAの機能を使い、PythonでUDFファイルを操作できるようになります。
udf=UDFManager(file_name)で、UDFファイルのインスタンスを作ります。
udf.get(location)で、UDF内のlocationが持っているデータを引数として返します。この時のlocationは、UDFパス名を書きます。

from UDFManager import UDFManager
import pandas as pd
import numpy as np
import os
path = "c:\path"
files = os.listdir(path)
filename = "filename_out.bdf"
openfile = path + '/' + filename
udf = UDFManager(openfile)
print(udf)

#dynamics_conditions
#time
max_force = udf.get('Simulation_Conditions.Dynamics_Conditions.Max_Force')
delta_t = udf.get('Simulation_Conditions.Dynamics_Conditions.Time.delta_T')
total_steps = udf.get('Simulation_Conditions.Dynamics_Conditions.Time.Total_Steps')
output_interval_steps = udf.get('Simulation_Conditions.Dynamics_Conditions.Time.Output_Interval_Steps')

time_list = (max_force,delta_t,total_steps,output_interval_steps)
time_list_s = pd.Series(time_list, index=['Max_Force', 'Time.delta_T', 'Time.Total_Steps','Time.Output_Interval_Steps'])

#temp
temperature = udf.get('Simulation_Conditions.Dynamics_Conditions.Temperature.Temperature')
interval_of_scale_temp = udf.get('Simulation_Conditions.Dynamics_Conditions.Temperature.Interval_of_Scale_Temp')

temp_list = (temperature,interval_of_scale_temp)
temp_list_s = pd.Series(temp_list,index=['Temperature','Temperature.Interval_of_Scale_Temp'])


#pressure
pressure = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Pressure')
stress_xx = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.xx')
stress_yy = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.yy')
stress_zz = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.zz')
stress_yz = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.yz')
stress_zx = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.zx')
stress_xy = udf.get('Simulation_Conditions.Dynamics_Conditions.Pressure_Stress.Stress.xy')

stress_list = (pressure,stress_xx,stress_yy,stress_zz,stress_yz,stress_zx,stress_xy)
stress_list_s = pd.Series(stress_list,index=['Pressure','Stress.xx','Stress.yy','Stress.zz','Stress.yz','Stress.zx','Stress.xy'])

#solver
solver_type = udf.get('Simulation_Conditions.Solver.Solver_Type')
dynamics_algorithm = udf.get('Simulation_Conditions.Solver.Dynamics.Dynamics_Algorithm')

solver_list = (solver_type,dynamics_algorithm)
solver_list_s = pd.Series(solver_list,index=['Solver_Type','Dynamics_Algorithm'])

#Boundary_Conditions
boundary_conditions_a_axis = udf.get('Simulation_Conditions.Boundary_Conditions.a_axis')
boundary_conditions_b_axis = udf.get('Simulation_Conditions.Boundary_Conditions.b_axis')
boundary_conditions_c_axis = udf.get('Simulation_Conditions.Boundary_Conditions.c_axis')
boundary_conditions_periodic_bond = udf.get('Simulation_Conditions.Boundary_Conditions.Periodic_Bond')

boundary_conditions_list = (boundary_conditions_a_axis,boundary_conditions_b_axis,boundary_conditions_c_axis,boundary_conditions_periodic_bond)
boundary_conditions_list_s = pd.Series(boundary_conditions_list,index=['a_axis','b_axis','c_axis','Periodic_Bond'])


#Calc_Potential_Flags.Bond
calc_potential_flags_bond = udf.get('Simulation_Conditions.Calc_Potential_Flags.Bond')
calc_potential_flags_angle = udf.get('Simulation_Conditions.Calc_Potential_Flags.Angle')
calc_potential_flags_torsion = udf.get('Simulation_Conditions.Calc_Potential_Flags.Torsion')
calc_potential_flags_non_bonding_interchain = udf.get('Simulation_Conditions.Calc_Potential_Flags.Non_Bonding_Interchain')
calc_potential_flags_non_bonding_intrachain = udf.get('Simulation_Conditions.Calc_Potential_Flags.Non_Bonding_Intrachain')
calc_potential_flags_non_bonding_1_3 = udf.get('Simulation_Conditions.Calc_Potential_Flags.Non_Bonding_1_3')
calc_potential_flags_non_bonding_1_4 = udf.get('Simulation_Conditions.Calc_Potential_Flags.Non_Bonding_1_4')
calc_potential_flags_external = udf.get('Simulation_Conditions.Calc_Potential_Flags.External')
calc_potential_flags_electrostatic = udf.get('Simulation_Conditions.Calc_Potential_Flags.Electrostatic')
calc_potential_flags_tail_correction = udf.get('Simulation_Conditions.Calc_Potential_Flags.Tail_Correction')

calc_potential_list = (calc_potential_flags_bond, calc_potential_flags_angle,calc_potential_flags_torsion,
								calc_potential_flags_non_bonding_interchain,calc_potential_flags_non_bonding_intrachain,calc_potential_flags_non_bonding_1_3,
								calc_potential_flags_non_bonding_1_4,calc_potential_flags_external,calc_potential_flags_electrostatic,calc_potential_flags_tail_correction)

calc_potential_list_s = pd.Series(calc_potential_list,index=['Bond','Angle','Torsion','Non_Bonding_Interchain','Non_Bonding_Intrachain','Non_Bonding_1_3',
								'Non_Bonding_1_4','External','Electrostatic','Tail_Correction'])

#Output_Flags_is_no_count
#Initial_Structure
initial_unit_cell_density = udf.get('Initial_Structure.Initial_Unit_Cell.Density')
initial_unit_cell_cell_size_a = udf.get('Initial_Structure.Initial_Unit_Cell.Cell_Size.a')
initial_unit_cell_cell_size_b = udf.get('Initial_Structure.Initial_Unit_Cell.Cell_Size.b')
initial_unit_cell_cell_size_c = udf.get('Initial_Structure.Initial_Unit_Cell.Cell_Size.c')
initial_unit_cell_cell_size_alpha = udf.get('Initial_Structure.Initial_Unit_Cell.Cell_Size.alpha')
initial_unit_cell_cell_size_beta = udf.get('Initial_Structure.Initial_Unit_Cell.Cell_Size.beta')
initial_unit_cell_shear_strain = udf.get('Initial_Structure.Initial_Unit_Cell.Shear_Strain')
initial_unit_cell_density = udf.get('Initial_Structure.Initial_Unit_Cell.Density')

initial_unit_cell_list = (initial_unit_cell_density, initial_unit_cell_cell_size_a,initial_unit_cell_cell_size_b,
								initial_unit_cell_cell_size_c ,initial_unit_cell_cell_size_alpha,initial_unit_cell_cell_size_beta,
								initial_unit_cell_shear_strain,initial_unit_cell_density)

initial_unit_cell_list_s = pd.Series(initial_unit_cell_list,index=['Density','Cell_Size.a','Cell_Size.b','Cell_Size.c','Cell_Size.alpha','Cell_Size.beta',
								'Shear_Strain','Density'])

#generated_method
generate_method_method= udf.get('Initial_Structure.Generate_Method.Method')
relaxation= udf.get('Initial_Structure.Relaxation.Relaxation')
relaxation_method= udf.get('Initial_Structure.Relaxation.Method')

generated_method_list = (generate_method_method, relaxation,relaxation_method)

generated_method_list_s = pd.Series(generated_method_list,index=['Method','Relaxation','Relaxation.Method'])

octa_pd = pd.concat([time_list_s, temp_list_s,stress_list_s,solver_list_s, boundary_conditions_list_s, calc_potential_list_s,initial_unit_cell_list_s,generated_method_list_s],axis=0)

savefile = path + '/' + filename + 'setteing_info.csv'

octa_pd.to_csv(savefile)









2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?