Skip to content

Instantly share code, notes, and snippets.

@hsofficial
Created February 5, 2025 05:31
Show Gist options
  • Save hsofficial/e8499346b2d92881a9b173598a3c18a7 to your computer and use it in GitHub Desktop.
Save hsofficial/e8499346b2d92881a9b173598a3c18a7 to your computer and use it in GitHub Desktop.
sdf2pdbconverter.sh
#!/bin/bash
# sdf2pdb converter, created by HS Na (dlwlrma@pusan.ac.kr)
# This script scans the file in the format [cid]_2d.sdf or [cid]_3d.sdf in the directory where the script ran and converts it to a pdb file via molconvert.
# scanning and parsing sdf file.
for sdf_file in *_[23]d.sdf; do
if [ -f "$sdf_file" ]; then
filename=$(basename "$sdf_file" .sdf)
cid=${filename%_*}
dimension=${filename##*_}
# generate output file name.
pdb_file="${cid}_${dimension}.pdb"
echo ">>> Converting $sdf_file to $pdb_file"
# Converting SDF to PDB using molconvert.
molconvert -3 pdb "$sdf_file" -o "$pdb_file"
# check converting status.
if [ $? -eq 0 ]; then
echo ">>> Conversion successful: $pdb_file"
else
echo ">>> Error converting $sdf_file"
fi
fi
done
echo ">>> All conversions completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment