-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermeability.py
More file actions
144 lines (106 loc) · 4.28 KB
/
permeability.py
File metadata and controls
144 lines (106 loc) · 4.28 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import MDAnalysis as mda
import numpy as np
import math
def calculate_num_atoms(file, selection):
"""
Calculates the average number of atoms in a specific region of a trajectory.
Parameters:
- file (str): Path to the XYZ file containing the trajectory.
- selection (str): Selection string for the atoms of interest.
Returns:
- num_atoms (float): Average number of atoms in the specified region.
Requires the MDAnalysis library: https://www.mdanalysis.org/
The function performs the following steps:
1. Loads the trajectory and topology.
2. Selects only the atoms in the specific region.
3. Calculates the number of atoms in each frame of the trajectory.
4. Returns the average number of atoms.
"""
u = mda.Universe(file)
num_atoms = []
for ts in u.trajectory[1:]:
atoms = u.select_atoms(selection)
num_atoms.append(len(atoms))
return np.mean(num_atoms)
def calculate_n_moles(n_atoms):
"""
Calculates the number of moles from the number of atoms.
Parameters:
- n_atoms (float): Number of atoms.
Returns:
- n_moles (float): Number of moles.
Uses Avogadro's constant for the conversion.
"""
avogadro = 6.022e23
n_moles = n_atoms / avogadro
return n_moles
def calculate_metal_area(lattice, atoms):
"""
Calculates the active metal area from the lattice cell size and the number of metal atoms.
Parameters:
- lattice (float): Lattice cell size in Angstrom.
- atoms (float): Number of metal atoms.
Returns:
- metal_area (float): Active metal area in square meters.
"""
area_atom = lattice ** 2 * math.sqrt(3/4)
metal_area = (atoms * area_atom) * 1e-20 # m²
return metal_area
def calculate_total_metal_area(lattice):
"""
Calculates the total metal area from the lattice cell size.
Parameters:
- lattice (float): Lattice cell size in Angstrom.
Returns:
- total_area (float): Total metal area in square meters.
"""
area_atom = lattice ** 2 * math.sqrt(3/4)
total_area = (492 * area_atom) * 1e-20 # m²
return total_area
def calculate_permeability(value, area):
"""
Calculates the permeability from a value and an area.
Parameters:
- value (float): Value to consider.
- area (float): Area in square meters.
Returns:
- permeability (float): Permeability in mol/(m²·s).
"""
permeability = value / area
return permeability
if __name__ == '__main__':
file = "/path/to/file.xyz"
# Calculate the average number of oxygen atoms on the active metal surface
selection = "name Ox and around 5 name Pt"
num_atoms = calculate_num_atoms(file, selection)
# Calculate the number of moles
n_moles = calculate_n_moles(num_atoms)
# Calculate the average number of metal atoms
selection = "name Pt and around 3.0 name O1"
atoms_Pt = calculate_num_atoms(file, selection)
# Define the lattice cell size
lattice_Pt = 3.92 # Angstrom
# Calculate active and inactive metal areas
area_active = calculate_metal_area(lattice_Pt, atoms_Pt)
area_inactive = calculate_metal_area(lattice_Pt, calculate_num_atoms(file, "name Pt and around 3.0 name Cgr C F O3 O4 S"))
# Calculate total metal area
total_area = calculate_total_metal_area(lattice_Pt)
# Calculate metal surface utilization
utilization = ((total_area - area_inactive) / total_area) * 100
# Calculate permeability
value = n_moles / (num_atoms * 10) # moles per picoseconds
permeability = calculate_permeability(value, area_active)
# Generate the results report
result_report = f"Results Report\n"
result_report += f"----------------\n"
result_report += f"Active metal area: {area_active} m²\n"
result_report += f"Inactive metal area: {area_inactive} m²\n"
result_report += f"Total metal area: {total_area} m²\n"
result_report += f"Metal surface utilization: {utilization}%\n"
result_report += f"Permeability per metal area: {permeability} mol/(m²·s)\n"
result_report += f"Average number of oxygen atoms on the metal surface in the trajectory: {num_atoms}\n"
# Save the report to a text file
with open("result_report.txt", "w") as f:
f.write(result_report)
# Print the report to the console
print(result_report)