def test_load_file(self):
     """
     Load an image from a file.
     """
     im = Image.fromarray(self.pixels, mode='RGB')
     _, filename = tempfile.mkstemp(suffix='.png')
     im.save(filename)
     im = image_utils.load(filename)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_file(self):
     """
     Load an image from a file.
     """
     im = Image.fromarray(self.pixels, mode="RGB")
     _, filename = tempfile.mkstemp(suffix=".png")
     im.save(filename)
     im = image_utils.load(filename)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_string(self):
     """
     Load an image from binary string.
     """
     im = Image.fromarray(self.pixels, mode='RGB')
     _, filename = tempfile.mkstemp(suffix='.png')
     im.save(filename)
     with open(filename) as f:
         string = f.read()
     im = image_utils.load(string)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_string(self):
     """
     Load an image from binary string.
     """
     im = Image.fromarray(self.pixels, mode="RGB")
     _, filename = tempfile.mkstemp(suffix=".png")
     im.save(filename)
     with open(filename) as f:
         string = f.read()
     im = image_utils.load(string)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
Esempio n. 5
0
    def depict(self, mol):
        """
        Generate a PNG image from a SMILES string.

        Parameters
        ----------
        mol : RDMol
            Molecule.
        size : int, optional (default 32)
            Size (in any direction) of generated image.
        """
        smiles = Chem.MolToSmiles(mol, isomericSmiles=True, canonical=True)
        args = ["obabel", "-i", "can", "-o", "png", "-xd", "-xC", "-xp {}".format(self.size)]
        p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        png, _ = p.communicate(smiles)
        im = image_utils.load(png)
        return im
Esempio n. 6
0
    def depict(self, mol):
        """
        Generate a PNG image from a SMILES string.

        Parameters
        ----------
        mol : RDMol
            Molecule.
        size : int, optional (default 32)
            Size (in any direction) of generated image.
        """
        smiles = Chem.MolToSmiles(mol, isomericSmiles=True, canonical=True)
        args = ['obabel', '-i', 'can', '-o', 'png', '-xd', '-xC',
                '-xp {}'.format(self.size)]
        p = subprocess.Popen(args, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        png, _ = p.communicate(smiles)
        im = image_utils.load(png)
        return im