Skip to content

Commit c5ed706

Browse files
authored
Merge pull request #797 from brucefan1983/tools_readme
fix readme in tools
2 parents 132da79 + 99c275e commit c5ed706

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

tools/cp2k2xyz/xyz2cp2k.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
#Read all frames of exyz and then calculate
4+
5+
# CP2K environment setup
6+
source /home/chen/software/cp2k-2024.1/tools/toolchain/install/setup
7+
export PATH=$PATH:/home/chen/software/cp2k-2024.1/exe/local
8+
9+
xyz_file="trj.xyz"
10+
template_inp="test.inp"
11+
12+
# Set the number of cores
13+
num_cores=48 # You can change this value as needed
14+
15+
# Debugging: Check the value of num_cores
16+
echo "Number of cores set to: $num_cores"
17+
18+
frame_number=0 # Current frame counter
19+
20+
while read -r line; do
21+
if [[ $line =~ ^[0-9]+$ ]]; then
22+
frame_number=$((frame_number + 1))
23+
atom_count=$line
24+
read -r frame_info
25+
# Extract Lattice information and split into three triplets
26+
lattice_values=$(echo $frame_info | grep -oP 'Lattice="\K[^"]+')
27+
IFS=' ' read -r lattice_a1 lattice_a2 lattice_a3 lattice_b1 lattice_b2 lattice_b3 lattice_c1 lattice_c2 lattice_c3 <<< "$lattice_values"
28+
29+
# Create a new input file
30+
new_inp="frame${frame_number}.inp"
31+
cp $template_inp $new_inp
32+
33+
# Modify the PROJECT line
34+
sed -i "s/^ PROJECT.*/ PROJECT frame${frame_number}/" $new_inp
35+
36+
# Modify the CELL line, only replace between &SUBSYS and &COORD
37+
sed -i "/&SUBSYS/,/&COORD/c\ &SUBSYS\n &CELL\n A ${lattice_a1} ${lattice_a2} ${lattice_a3}\n B ${lattice_b1} ${lattice_b2} ${lattice_b3}\n C ${lattice_c1} ${lattice_c2} ${lattice_c3}\n PERIODIC XYZ #Direction(s) of applied PBC (geometry aspect)\n &END CELL\n &COORD" $new_inp
38+
39+
# Clear the COORD content
40+
sed -i '/&COORD/,/&END COORD/c\ &COORD\n &END COORD' $new_inp
41+
42+
# Read atom coordinates and write to the new input file
43+
for ((i=0; i<atom_count; i++)); do
44+
read -r atom_line
45+
# Extract element symbol and coordinate information
46+
IFS=' ' read -r element x y z _ <<< "$atom_line"
47+
sed -i "/&COORD/a\ $element $x $y $z" $new_inp
48+
done
49+
fi
50+
done < $xyz_file
51+
52+
# Running CP2K for each input file
53+
for inp_file in frame*.inp; do
54+
# Debugging: Print the command that will be run
55+
echo "Running: mpirun -np $num_cores cp2k.popt $inp_file"
56+
mpirun -np $num_cores cp2k.popt $inp_file | tee "${inp_file%.inp}.out"
57+
done
58+
59+
# Merging output files
60+
merged_cell_file="merged.cell"
61+
merged_frc_file="merged-frc-1.xyz"
62+
merged_pos_file="merged-pos-1.xyz"
63+
64+
# Remove old merged files if they exist
65+
rm -f $merged_cell_file $merged_frc_file $merged_pos_file
66+
67+
# Concatenate each type of file
68+
for frame_number in $(seq 1 $frame_number); do
69+
cat "frame${frame_number}-1.cell" >> $merged_cell_file
70+
cat "frame${frame_number}-frc-1.xyz" >> $merged_frc_file
71+
cat "frame${frame_number}-pos-1.xyz" >> $merged_pos_file
72+
done
73+
74+
# Process merged.cell to retain only the first comment line
75+
awk '!/^#/ || !found { if (/^#/) found=1; print }' $merged_cell_file > temp && mv temp $merged_cell_file
76+
77+
# Clean up individual frame files and input files
78+
for frame_number in $(seq 1 $frame_number); do
79+
rm -f "frame${frame_number}.inp" "frame${frame_number}-1.cell" "frame${frame_number}-frc-1.xyz" "frame${frame_number}-pos-1.xyz" "frame${frame_number}.out" "frame${frame_number}-1.restart" "frame${frame_number}-1.ener"
80+
done
104 KB
Binary file not shown.

tools/readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
| -------------------- | ------------ | ------------------------------------------------------------ |
1010
| abacus2xyz | Benrui Tang | Get `train.xyz` from `ABACUS` outputs. |
1111
| add_groups | Yuwen Zhang | Generate grouping method(s) for `model.xyz`. |
12-
| castep2exyz | Zerui Chen | Get `train.xyz` from `CP2K` outputs. |
12+
| castep2exyz | Yanzhou Wang | Get `train.xyz` from `CASTEP` outputs. |
13+
| cp2k2xyz | Zherui Chen | Get `train.xyz` from `CP2K` outputs or vice versa. |
1314
| deep2nep | Ke Xu | Oudated? |
1415
| doc_3.3.1 | Zheyong Fan | Documentation for some parts of GPUMD-v3.3.1. |
1516
| dp2xyz | Ke Xu | Convert `DP` training data to xyz format. |
@@ -28,6 +29,6 @@
2829
| split_xyz | Yong Wang | Some functionalities for trainnig/test data. |
2930
| vasp2xyz | Yanzhou Wang | Get `train.xyz` from `VASP` outputs. |
3031
| vim | Ke Xu | Highlight GPUMD grammar in `vim`. |
31-
| xyz2gro | Zerui Chen | Convert `xyz` file to `gro` file. |
32+
| xyz2gro | Zherui Chen | Convert `xyz` file to `gro` file. |
3233
| [NepTrainKit](https://github.com/aboys-cb/NepTrainKit) | Chengbing Chen| NEP data visualization interface program |
3334

0 commit comments

Comments
 (0)