pypackmol (in RMC_DFT)
A Python package for simplifying the use of Packmol (Nakada)
Official Packmol website
Linux
wget https://m3g.iqm.unicamp.br/packmol/packmol.tar.gz
tar xzf packmol.tar.gz
cd packmol
make
macOS
brew install gcc
tar xzf packmol.tar.gz
cd packmol
FC=gfortran-14 F77=gfortran-14 ./configure
make
Add the directory to your PATH, or copy the executable to a directory on your PATH.
Official Packmol module
Not used
https://github.com/m3g/Packmol.jl#packmol
This is simply a wrapper that launches Packmol via subprocess.
Input file (packmol.inp)
rmc_dft.packmol.packmol.Packmol
Basic usage example 1
from x_logger import XLogger
from rmc_dft.packmol.packmol import Packmol
def main() -> None:
logger = XLogger()
comment = "FeSiB amorphous generated by Packmol"
PACKMOL = "/Users/nakada/packmol/bin/packmol"
result_xyz_file = "amorphous/FeSiB_amorphous.xyz"
Fe_xyz_file = "amorphous/Fe.xyz"
Si_xyz_file = "amorphous/Si.xyz"
B_xyz_file = "amorphous/B.xyz"
##########################
N_tot = 500 # Number of atoms in the cell
rho_g_cm3 = 7.35 # Mass density
ratios = [80, 9, 11] # Stoichiometric ratios
symbols = ["Fe", "Si", "B"]
##########################
pm = Packmol()
n_per_A3 = pm.number_density_from_mass_density(symbols, ratios, rho_g_cm3)
# mass_density_g_cm3 = pm.mass_density_from_number_density(symbols, ratios, number_density_A3)
# Fe-Si-B の総原子数からそれぞれの原子数を決める,Stoichiometric ratiosはすでに決定済み
counts = pm.compute_element_counts(symbols, ratios, N_tot)
N_Fe = counts["Fe"]
N_Si = counts["Si"]
N_B = counts["B"]
L = pm.cell_length_from_number_density(N_tot, n_per_A3)
logger.info(f'{counts}')
logger.info(f'L = {L:.6f}')
with open(result_xyz_file, "w") as f:
f.write("tolerance 2.0\n")
f.write("filetype xyz\n")
f.write(f"output {result_xyz_file}\n\n")
# Fe
f.write(f"structure {Fe_xyz_file}\n")
f.write(f" number {N_Fe}\n")
f.write(f" inside box 0.0 0.0 0.0 {L:.6f} {L:.6f} {L:.6f}\n")
f.write("end structure\n\n")
# Si
f.write(f"structure {Si_xyz_file}\n")
f.write(f" number {N_Si}\n")
f.write(f" inside box 0.0 0.0 0.0 {L:.6f} {L:.6f} {L:.6f}\n")
f.write("end structure\n\n")
# B
f.write(f"structure {B_xyz_file}\n")
f.write(f" number {N_B}\n")
f.write(f" inside box 0.0 0.0 0.0 {L:.6f} {L:.6f} {L:.6f}\n")
f.write("end structure\n")
# --- structure file generation ---
pm.write_single_atom_xyz("Fe.xyz", "Fe")
pm.write_single_atom_xyz("Si.xyz", "Si")
pm.write_single_atom_xyz("B.xyz", "B")
# Run Packmol automatically
pm.run_packmol(packmol_bin=PACKMOL)
# POSCAR
pm.xyz_to_poscar(
"FeSiB_amorphous.xyz",
"POSCAR",
comment=comment,
elements=["Fe", "Si", "B"],
)
if __name__ == "__main__":
main()
rmc_dft.packmol.PackmolInp
Generalization of the preceding script using the input-file generation class