#! /bin/bash # which schema contains desired functions; gnova,openbabel,frowns,perlmol # take your pick of options to psql PSQL='psql -t -A -P fieldsep=,' PSQL='psql -H' PSQL='psql -t -A' # schema where core chemical functions are: gnova,openbabel,frowns,perlmol FUNC="openbabel" _molgrep() { $PSQL -c "Select isosmiles,name from \"$2\".structure where $FUNC.contains(fp, $FUNC.fp('$3')) and $FUNC.matches(isosmiles, '$3')" } _molcat() { $PSQL -c "Select isosmiles,name from \"$2\".structure" } _molview() { echo "" if [ "$3" == "" ]; then $PSQL -c "Select marvin_view(isosmiles) from \"$2\".structure" else $PSQL -c "Select marvin_view(isosmiles,'$3') from \"$2\".structure" fi } _molarb() { $PSQL -c "Select isosmiles,name from \"$2\".structure order by md5(id+$4) limit $3" } _molrandom() { $PSQL -c "Select isosmiles,name from \"$2\".structure order by md5(id+$RANDOM) limit $3" } _molnear() { $PSQL -c "Select isosmiles,name,tanimoto(fp, $FUNC.fp('$3')) from \"$2\".structure where tanimoto(fp, $FUNC.fp('$3')) > $4" } _molsame() { $PSQL -c "select isosmiles,name from \"$2\".structure where isosmiles in (select isosmiles from \"$2\".structure intersect select isosmiles from \"$3\".structure)" } _moldir() { psql -c "\dt *.structure" } ME=./dbutils # could be /usr/local/bin/dbutils cmd="$0" if [ "$cmd" == "bash" ]; then alias molgrep="$ME _molgrep" alias molcat="$ME _molcat" alias molview="$ME _molview" alias molrandom="$ME _molrandom" alias molarb="$ME _molarb" alias molnear="$ME _molnear" alias molsame="$ME _molsame" alias moldir="$ME _moldir" else $1 $* fi