This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LammpsStrBCC.m
93 lines (78 loc) · 3.19 KB
/
LammpsStrBCC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function [varargout] = LammpsStrBCC(varargin)
%% Description
% function [varargout] = LammpsStrBCC(num_cell,lattice_const,atom_type,atom_charge)
%
% Input:
%
% data_cell : coordinate of cell points, created by function
% LammpsStrCellCoord
%
% lattice_const : lattice constant of struture.
%
% atom_type : *Case 1* : atom_type = 1, all atom will be set to type 1;
% *Case 2* : atom_type = 2, each atom in cell will get an
% unique type
% *Case 3* : atom_type is matric. each of atom will be set
% to type correspond number in matric. Matric lenghth
% should be equal to # of atoms in cell strickly.
%
% atom_charge : *Case 1* : atom_charge = 0; All atom charge will be set
% to 0.
% *Case 2* : atom_charge single number. All atom will be set
% to the same charge.
% *Case 3* : atom_charge is a matric. Each atom will be set
% to a charge correspond number in matric. Same as Case 3
% of atom_type, length of matric should be equal to
% number of atoms in cell
%% Struture data
lattice_const = varargin{2};
str_mtr = [
0 0 0
0.5 0.5 0.5
]; % Normalized vectors of atom coordinate in cell
cell_vector = [
lattice_const 0 0
0 lattice_const 0
0 0 lattice_const;
]; % Vectors that determining cell size
%% Reading Input
data_cell = varargin{1};
num_cell_tot = data_cell(1).num_cells;
[num_cell_atoms,num_dims] = size(str_mtr);
num_atoms = num_cell_tot*num_cell_atoms;
if varargin{3} == 1
atom_type = ones(num_cell_atoms,1);
num_atom_types = 1;
elseif varargin{3} == 2;
atom_type = 1:num_cell_atoms;
num_atom_types = num_cell_atoms;
else
num_atom_types = length(atom_type);
end
if varargin{4} == 0
atom_charge = zeros(num_cell_atoms,1);
elseif length(varargin{4}) == 1
atom_charge = ones(num_cell_atoms,1) * varargin{4};
end
atom_style = 'full';
fprintf("# of atoms: %d\n",num_atoms)
%% Writing Data File
box_size = data_cell.box_size .* lattice_const;
for cell_now = 1 : data_cell.num_cells
for atom = 1 : num_cell_atoms
id_now = (cell_now - 1) * num_cell_atoms + atom;
data_atom(id_now,1) = (cell_now - 1) * num_cell_atoms + atom;
data_atom(id_now,2) = cell_now;
data_atom(id_now,3) = atom_type(atom);
data_atom(id_now,4) = atom_charge(atom);
data_atom(id_now,5:7) = data_cell.coord_cell(cell_now,:) * cell_vector + str_mtr(atom,:) * cell_vector;
end
end
%% ---------------------Output-----------------------------
% Box Info
varargout{1}.box_size = box_size;
% Atom Info
varargout{1}.data_atom = data_atom;
varargout{1}.atom_style = atom_style;
varargout{1}.num_atoms = num_atoms;
varargout{1}.num_atom_types = num_atom_types;