Skip to content

Commit

Permalink
Merge pull request #144 from kalinni/bug/magick
Browse files Browse the repository at this point in the history
Updates ImageMagick to version 7 and makes its use platform independent
  • Loading branch information
fkaiserbio committed Aug 18, 2023
2 parents 40671fd + b04d7f0 commit c429d14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If you cannot use the containerized bundle or want to use PLIP sources, make sur
- Python >= 3.6.9
- [OpenBabel](#Installing-OpenBabel) >= 3.0.0 with [Python bindings](https://open-babel.readthedocs.io/en/latest/UseTheLibrary/PythonInstall.html)
- PyMOL >= 2.3.0 with Python bindings (optional, for visualization only)
- ImageMagick >= 6.9 (optional)
- ImageMagick >= 7.0 (optional)

**Python:** If you are on a system where Python 3 is executed using `python3` instead of just `python`, replace the `python` and `pip` commands in the following steps with `python3` and `pip3` accordingly.

Expand Down Expand Up @@ -164,7 +164,7 @@ Using PLIP in your commercial or non-commercial project is generally possible wh
If you are using PLIP in your work, please cite
> Adasme,M. et al. PLIP 2021: expanding the scope of the protein-ligand interaction profiler to DNA and RNA.
> Nucl. Acids Res. (05 May 2021), gkab294. doi: 10.1093/nar/gkab294
or

> Salentin,S. et al. PLIP: fully automated protein-ligand interaction profiler.
Expand Down
24 changes: 16 additions & 8 deletions plip/visualization/pymol.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,29 @@ def png_workaround(filepath, width=1200, height=800):
os.rename(originalfile, newfile) # Remove frame number in filename

# Check if imagemagick is available and crop + resize the images
if subprocess.call("type convert", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
if subprocess.call("magick -version", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
attempts, ecode = 0, 1
# Check if file is truncated and wait if that's the case
while ecode != 0 and attempts <= 10:
ecode = subprocess.call(['convert', newfile, '/dev/null'], stdout=open('/dev/null', 'w'),
ecode = subprocess.call(['magick', newfile, os.devnull], stdout=open(os.devnull, 'w'),
stderr=subprocess.STDOUT)
sleep(0.1)
attempts += 1
trim = 'convert -trim ' + newfile + ' -bordercolor White -border 20x20 ' + newfile + ';' # Trim the image
trim = f'magick {newfile} -trim -bordercolor White -border 20x20 {newfile}' # Trim the image
os.system(trim)
getwidth = 'w=`convert ' + newfile + ' -ping -format "%w" info:`;' # Get the width of the new image
getheight = 'h=`convert ' + newfile + ' -ping -format "%h" info:`;' # Get the hight of the new image
newres = 'if [ "$w" -gt "$h" ]; then newr="${w%.*}x$w"; else newr="${h%.*}x$h"; fi;' # Set quadratic ratio
quadratic = 'convert ' + newfile + ' -gravity center -extent "$newr" ' + newfile # Fill with whitespace
os.system(getwidth + getheight + newres + quadratic)
# Get the width of the new image
getwidth = f'magick {newfile} -ping -format "%w" info:'
w = int(subprocess.run(getwidth, capture_output=True, text=True).stdout)
# Get the hight of the new image
getheight = f'magick {newfile} -ping -format "%h" info:'
h = int(subprocess.run(getheight, capture_output=True, text=True).stdout)
# Set quadratic ratio
if w > h:
newr= f'{w}x{w}'
else:
newr= f'{h}x{h}'
quadratic = f'magick {newfile} -gravity center -extent {newr} {newfile}' # Fill with whitespace
os.system(quadratic)
else:
sys.stderr.write('Imagemagick not available. Images will not be resized or cropped.')

Expand Down

0 comments on commit c429d14

Please sign in to comment.