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
|
#!/bin/sh
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2021-04-28 19:35:53 +0300 (Wed, 28 Apr 2021) $
#$Revision: 8738 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.7.0/scripts/cif_CODify $
#------------------------------------------------------------------------------
#*
#* Extract essential data from the input CIF file and format it
#* using the rules of the Crystallography Open Database (COD).
#*
#* USAGE:
#* $0 1000000.cif
#* $0 4000042.cif --options
#**
set -ue
# set -x
CIF_FILTER="cif_filter"
CIF_FILE=""
ARGS=""
while [ $# -gt 0 ]
do
case $1 in
--options|--option|--optio|--opti|--opt|--op|--o)
echo "$(basename "$0"):: The '--options' option is a placeholder."
echo "$(basename "$0"):: It should be replaced by one of the following options:"
awk '/#\* OPTIONS:/,/#\*\*/ {
sub("OPTIONS:", "");
sub("^ *#[*]?[*]?", "");
gsub("\\$0","'"$0"'");
print $0
}' $(dirname $0)/${CIF_FILTER}
echo "$0:: NOTE, the option list was retrieved from the '${CIF_FILTER}' script."
exit
;;
--help|--hel|--he|--h|--usage)
gawk '/^#\*/,/^#\*\*/ {
sub("^ *#[*]?[*]?", "");
gsub("\\$0","'"$0"'");
print $0
}' "$0"
awk '/#\* OPTIONS:/,/#\*\*/ {
sub("^ *#[*]?[*]?", "");
gsub("\\$0","'"$0"'");
print $0
}' "$(dirname "$0")"/${CIF_FILTER}
echo "$0:: NOTE, the option list was retrieved from the '${CIF_FILTER}' script."
exit
;;
--version)
$(dirname $0)/cod-tools-version
exit
;;
*)
if [ -z "${CIF_FILE}" ];
then
CIF_FILE=$1
else
ARGS="${ARGS} $1"
fi
;;
esac
shift
done
if [ -z "${CIF_FILE}" ];
then
echo "$0:: ERROR, the mandatory input CIF file was not provided." 1>&2
exit 1;
fi
if head "${CIF_FILE}" | grep -q '^#' > /dev/null 2>&1
then
awk '{if( match( $0, "^#" )) print; else exit}' "${CIF_FILE}"
else
cat <<EOF
#------------------------------------------------------------------------------
#\$Date\$
#\$Revision\$
#\$URL\$
#------------------------------------------------------------------------------
#
# This file is available in the Crystallography Open Database (COD),
# http://www.crystallography.net/
#
# All data on this site have been placed in the public domain by the
# contributors.
#
EOF
fi
NUMBER=`basename "${CIF_FILE}" .cif | sed -e 's/[^0-9]//g'`
${CIF_FILTER} \
--renumber \
--start-data="${NUMBER}" \
--exclude-empty-non-loop-tags \
--estimate-spacegroup \
--reformat-spacegroup \
--keep-unrecognised-spacegroup \
--parse-formula-sum \
--calculate-cell-volume \
--use-all-datablocks \
"${CIF_FILE}" ${ARGS}
|