Skip to content

Commit

Permalink
ss/MASTER added new code for 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sulstice committed Jun 19, 2020
1 parent 101b2e8 commit fadecec
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
include README.md requirements.in requirements.txt
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -74,7 +74,7 @@ Generate a List a PDF of Amino Acids
document.add_spacer()
smiles_amino_acids = list(amino_acid_side_chains.values())
document.generate(smiles=smiles_amino_acids)
document.generate(smiles=smiles_amino_acids, include_failed_smiles=True)
```

Expand Down
Binary file added examples/functional_groups.pdf
Binary file not shown.
19 changes: 14 additions & 5 deletions molpdf/molpdf.py
Expand Up @@ -325,26 +325,35 @@ def add_title(self, title):
title = Paragraph(title, self.styles['Line_Label_Center_Big'])
self.story.append(title)

def add_image(self, smiles, temporary_directory):
def add_image(self, smiles, temporary_directory, include_failed_smiles=False):

"""
Arguments:
smiles (String): smiles representation of the molecule
temporary_directory (tempfile object): Temporary directory of the module
include_failed_smiles (Bool): whether the user would like to include failed smiles.
"""

indigo = Indigo()
renderer = IndigoRenderer(indigo)

molecule = indigo.loadMolecule(smiles)
try:
molecule = indigo.loadMolecule(smiles)
except IndigoException as e:
if include_failed_smiles:
self.add_row("Failed Rendering", smiles)
return

molecule.layout() # if not called, will be done automatically by the renderer
indigo.setOption("render-output-format", "png")
indigo.setOption("render-image-size", 400, 400)
indigo.setOption("render-background-color", 1.0, 1.0, 1.0)

path = os.path.join(temporary_directory, smiles + '.png')
import uuid

path = os.path.join(temporary_directory, str(uuid.uuid4()) + '.png')

renderer.renderToFile(molecule, filename=path)
image = Image(path, 1 * inch, 1 * inch, hAlign='CENTER')
Expand Down Expand Up @@ -421,7 +430,7 @@ def add_row(self, image, smiles):
self.story.append(table)

@timeit
def generate(self, smiles):
def generate(self, smiles, include_failed_smiles=False):


"""
Expand All @@ -440,7 +449,7 @@ def generate(self, smiles):
self.smiles = smiles

for smiles in self.smiles:
self.add_image(smiles, tmp)
self.add_image(smiles, tmp, include_failed_smiles)

# Build the initial PDF using Reportlab
self.doc.build(self.story)
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
@@ -1,6 +1,9 @@
epam.indigo==1.4.0b0
numpy==1.18.3
opencv-python==4.2.0.34
pdfminer==20191125
pdfrw==0.4
Pillow==7.1.1
pycryptodome==3.9.7
reportlab==3.5.42
six==1.14.0
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -35,7 +35,7 @@
# ----
setup(
name="molpdf",
version="0.2.0",
version="0.3.0",
packages=['molpdf'],
license='MPL 2.0',
author="Suliman Sharif",
Expand Down

0 comments on commit fadecec

Please sign in to comment.