示例#1
0
    def __init__(self, mol=None, parent=None):
        #Also init the super class
        super(MolEditWidget, self).__init__(parent)
        #This sets the window to delete itself when its closed, so it doesn't keep querying the model
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        #Properties
        self._prevmol = None  #For undo
        self.coordlist = None  #SVG coords of the current mols atoms

        #Standard atom types
        self.symboltoint = symboltoint

        self.bondtypes = Chem.rdchem.BondType.names  #A dictionary with all available rdkit bondtypes

        #Default actions
        self._action = "Add"
        self._bondtype = self.bondtypes["SINGLE"]
        self._atomtype = 6

        #Points to calculate the SVG to coord scaling
        self.points = [Point2D(0, 0), Point2D(1, 1)]

        #Bind signals to slots
        self.finishedDrawing.connect(
            self.update_coordlist
        )  #When drawing finished, update coordlist of SVG atoms.

        #Init with a mol if passed at construction
        #if mol != None:
        self.mol = mol
示例#2
0
    def SVG_to_coord(self, x_svg, y_svg):
        if self.drawer != None:
            scale0 = self.drawer.GetDrawCoords(self.points[0])
            scale1 = self.drawer.GetDrawCoords(self.points[1])

            ax = scale1.x - scale0.x
            bx = scale0.x

            ay = scale1.y - scale0.y
            by = scale0.y

            return Point2D((x_svg - bx) / ax, (y_svg - by) / ay)
        else:
            return Point2D(0., 0.)
示例#3
0
 def computeNewCoords(self, ignoreExisting=False):
     """Computes new coordinates for the molecule taking into account all
     existing positions (feeding these to the rdkit coordinate generation as
     prev_coords).
     """
     # This code is buggy when you are not using the CoordGen coordinate
     # generation system, so we enable it here
     rdDepictor.SetPreferCoordGen(True)
     prev_coords = {}
     if self._mol.GetNumConformers() == 0:
         self.logger.debug("No Conformers found, computing all 2D coords")
     elif ignoreExisting:
         self.logger.debug("Ignoring existing conformers, computing all "
                           "2D coords")
     else:
         assert self._mol.GetNumConformers() == 1
         self.logger.debug("1 Conformer found, computing 2D coords not in "
                           "found conformer")
         conf = self._mol.GetConformer(0)
         for a in self._mol.GetAtoms():
             pos3d = conf.GetAtomPosition(a.GetIdx())
             if (pos3d.x, pos3d.y) == (0, 0):
                 continue
             prev_coords[a.GetIdx()] = Point2D(pos3d.x, pos3d.y)
     rdDepictor.Compute2DCoords(self._mol, coordMap=prev_coords)
示例#4
0
    def read(self):
        #found randomly online: https://binfalse.de/software/parseable-biodata/amino-acids/
        table = r'''Alanine Ala     A       C3H7NO2 O=C(O)C(N)C     nonpolar        neutral 1.8     nonessential    6.01    2.35    9.87
Arginine        Arg     R       C6H14N4O2       O=C(O)C(N)CCC/[NH+]=C(\[NH2])[NH2]  polar   positive        −4.5    essential       10.76   1.82    8.99
Asparagine      Asn     N       C4H8N2O3        O=C(N)CC(N)C(=O)O   polar   neutral −3.5    nonessential    5.41    2.14    8.72
Asparticacid    Asp     D       C4H7NO4 O=C(O)CC(N)C(=O)[O-]       polar   negative        −3.5    nonessential    2.85    1.99    9.90
Cysteine        Cys     C       C3H7NO2S        C(C(C(=O)O)N)S     nonpolar        neutral 2.5     nonessential    5.05    1.92    10.70
Glutamicacid    Glu     E       C5H9NO4 C(CC(=O)[O-])C(C(=O)O)N    polar   negative        −3.5    nonessential    3.15    2.10    9.47
Glutamine       Gln     Q       C5H10N2O3       O=C(N)CCC(N)C(=O)O      polar   neutral −3.5    nonessential    5.65    2.17    9.13
Glycine Gly     G       C2H5NO2 C(C(=O)O)N      nonpolar        neutral −0.4    nonessential    6.06    2.35    9.78
Histidine       His     H       C6H9N3O2        O=C(C(CC1=CNC=N1)N)O polar   neutral(90%)−3.2        essential       7.60    1.80    9.33
Isoleucine      Ile     I       C6H13NO2        CC[C@H](C)C(C(=O)O)N       nonpolar        neutral 4.5     essential       6.05    2.32    9.76
Leucine Leu     L       C6H13NO2        CC(C)CC(C(=O)O)N   nonpolar        neutral 3.8     essential       6.01    2.33    9.74
Lysine  Lys     K       C6H14N2O2       C(CC[NH3+])CC(C(=O)O)N       polar   positive        −3.9    essential       9.60    2.16    9.06
Methionine      Met     M       C5H11NO2S       CSCCC(C(=O)O)N  nonpolar        neutral 1.9     essential       5.74    2.13    9.28
Phenylalanine   Phe     F       C9H11NO2        c1ccc(cc1)CC(C(=O)O)N      nonpolar        neutral 2.8     essential       5.49    2.20    9.31
Proline Pro     P       C5H9NO2 C1CC(NC1)C(=O)O nonpolar        neutral −1.6    nonessential    6.30    1.95    10.64
Serine  Ser     S       C3H7NO3 C(C(C(=O)O)N)O     polar   neutral −0.8    nonessential    5.68    2.19    9.21
Threonine       Thr     T       C4H9NO3 C[C@H](C(C(=O)O)N)O        polar   neutral −0.7    essential       2.09    2.09    9.10
Tryptophan      Trp     W       C11H12N2O2      c1ccc2c(c1)c(c[nH]2)CC(C(=O)O)N    nonpolar        neutral −0.9    essential       5.89    2.46    9.41
Tyrosine        Tyr     Y       C9H11NO3        NC(Cc1ccc(O)cc1)C(O)=O     polar   neutral −1.3    nonessential    5.64    2.20    9.21
Valine  Val     V       C5H11NO2        CC(C)C(C(=O)O)N    nonpolar        neutral 4.2     essential       6.00    2.39    9.74'''
        aminoacids = {}  # single letter to mol.
        for aa in table.split('\n'):
            a = aa.split()
            mol = Chem.MolFromSmiles(a[4])
            AllChem.Compute2DCoords(mol)
            mol.SetProp('_Name', a[0])
            if a[0] == 'Proline':
                self.fix_carboxy(mol)
            else:
                self.fix_backbone(mol)
            aminoacids[a[2]] = mol
        ref = Chem.MolFromSmiles('NCC(=O)O')
        AllChem.Compute2DCoords(ref,
                                coordMap={
                                    0: Point2D(0, 0),
                                    1: Point2D(0, 1.34),
                                })
        for name1, mol in aminoacids.items():
            AllChem.GenerateDepictionMatching2DStructure(mol, ref)
        return aminoacids