Hi Thomas,

oops, sorry, I gave a quick look at your script and I misinterpreted the meaning of the headers without actually reading the code.


TL;DR: the fix is to reshape the numpy array before passing it to AllChem.TransformMol:

tmatinv1 = np.array(linalg.inv(tmatinv), order='C')

Boring explanation:

Having investigated this by adding some debugging printout to the C++ code, the reason of the odd behaviour is that linalg.inv changes the order in which the data is stored in the array from row-major to column-major, so when the C++ transConformer() function extracts the raw data from the numpy array, extracts it in the wrong order.

inData shows how the data are extracted by the C++ code. This is the output of your original script:

<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.   0.   0.   0.5]
 [ 0.   1.   0.   0. ]
 [ 0.   0.   1.   0. ]
 [ 0.   0.   0.   1. ]]
float64
<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.   0.   0.  -0.5]
 [ 0.   1.   0.   0. ]
 [ 0.   0.   1.   0. ]
 [ 0.   0.   0.   1. ]]
float64
<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.  -0.  -0.   0.5]
 [-0.   1.  -0.  -0. ]
 [-0.  -0.   1.  -0. ]
 [-0.  -0.  -0.   1. ]]
float64


original coordinates:

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    1.2080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    2.4443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END

nrows = 4
dSize = 16
inData = 1,0,0,-0.5,0,1,0,0,0,0,1,0,0,0,0,1



TransformMol with explicit inverse -> coordinates change:

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    0.7080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.9443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END



second TransformMol with calculated inverse -> coordinates dont change:

nrows = 4
dSize = 16
inData = 1,-0,-0,-0,-0,1,-0,-0,-0,-0,1,-0,0.5,-0,-0,1

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    0.7080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.9443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END

And this is the expected output after reshaping the array to row-major order, by changing

tmatinv1 = linalg.inv(tmatinv)

into

tmatinv1 = np.array(linalg.inv(tmatinv), order='C'):

<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.   0.   0.   0.5]
 [ 0.   1.   0.   0. ]
 [ 0.   0.   1.   0. ]
 [ 0.   0.   0.   1. ]]
float64
<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.   0.   0.  -0.5]
 [ 0.   1.   0.   0. ]
 [ 0.   0.   1.   0. ]
 [ 0.   0.   0.   1. ]]
float64
<type 'numpy.ndarray'>
<type 'numpy.float64'>
[[ 1.  -0.  -0.   0.5]
 [-0.   1.  -0.  -0. ]
 [-0.  -0.   1.  -0. ]
 [-0.  -0.  -0.   1. ]]
float64


original coordinates:

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    1.2080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    2.4443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END

nrows = 4
dSize = 16
inData = 1,0,0,-0.5,0,1,0,0,0,0,1,0,0,0,0,1



TransformMol with explicit inverse -> coordinates change:

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    0.7080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.9443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -0.5000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.7080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END



second TransformMol with calculated inverse -> coordinates dont change:

nrows = 4
dSize = 16
inData = 1,-0,-0,0.5,-0,1,-0,-0,-0,-0,1,-0,-0,-0,-0,1

BH
     RDKit          3D

  7  7  0  0  0  0  0  0  0  0999 V2000
    1.2080    0.6971    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    2.4443    1.4118    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000    1.3951    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080    0.6981    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
   -1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    0.0000   -1.3949    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
    1.2080   -0.6979    0.0000 C   0  0  0  0  0  0  0 0  0  0  0  0
  1  2  1  0
  1  3  2  0
  1  7  1  0
  3  4  1  0
  4  5  2  0
  5  6  1  0
  6  7  2  0
M  END

So, the fix is to reshape the numpy array before passing it to AllChem.TransformMol.

Cheers,
p.


On 10/17/17 16:35, thomas....@boehringer-ingelheim.com wrote:

Hi Paolo,

thanks for looking into this.

However, when you look into the code (maybe I should have made this clearer) the second and third results should **not** be the same. So I ‘TranslateMol’ the compound twice, but only the first TranslateMol has an effect, the second one doesn’t change the coordinates, although it should.

But good to know that you get the same results as I do – probably should have attached my output as well…done now. And a diff with your test.log shows no differences…

Best,
Th.

Mit freundlichen Grüßen / Kind regards,
Dr. Thomas Fox

Boehringer Ingelheim Pharma GmbH & Co. KG
Medicinal Chemistry
Tel.: +49 (7351) 54-7585
Fax: +49 (7351) 83-7585
mailto:thomas....@boehringer-ingelheim.com <mailto:%7bemail%7d>

Pflichtangaben finden Sie unter:https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland Mandatory information can be found at: https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland

Diese E-Mail ist vertraulich zu behandeln. Sie kann besonderem rechtlichem Schutz unterliegen. Wenn Sie nicht der richtige Adressat sind, senden Sie bitte diese E-Mail an den Absender zurück, löschen die eingegangene E-Mail und geben den Inhalt der E-Mail nicht weiter. Jegliche unbefugte Bearbeitung, Nutzung, Vervielfältigung oder Verbreitung ist verboten. / This e-mail is confidential and may also be legally privileged. If you are not the intended recipient please reply to sender, delete the e-mail and do not disclose its contents to any person. Any unauthorized review, use, disclosure, copying or distribution is strictly prohibited.

*Von:*Paolo Tosco [mailto:paolo.to...@unito.it]
*Gesendet:* Dienstag, 17. Oktober 2017 17:08
*An:* Fox,Dr.,Thomas (RES MedChem) BIP-DE-B
*Betreff:* Re: [Rdkit-discuss] GetAlignmentTransform

Dear Thomas,

I have just run your Python script and I get the same output in both cases (see attachment). I am not using Anaconda Python though; I wonder if this makes the difference.

Cheers,
p.

On 10/17/17 13:48, thomas....@boehringer-ingelheim.com <mailto:thomas....@boehringer-ingelheim.com> wrote:

    Hi,

    here’s another one, unfortunately wasn’t yet able to figure out a
    solution:

    Once I have the transformation matrix from GetAlignmentTransform,
    I want to use it in TransformMol.

    So, when I use it as is, things work. When I calculate the inverse
    of it  with linalg.inv and feed the resulting matrix into
    TransformMol, nothing happens, the coordinates stay the same. No
    error message either…

    When I however, print out the inverse matrix and set it explicitly
    in the code (does not make sense for a real-life script, only for
    testing) the molecule is transformed as desired.

    In the attached python code I have demonstrated this by using a
    translation in x-direction by 0.5 A.

    Explicitly declaring the inverse transformation (ie. Translation
    by -0.5A) and applying it works, feeding the calculated inverse
    matrix into TransformMol results in unchanged atomic positions.

    And again, printing out the arrays (and checking the types!) I
    don’t see any difference…

    Thanks for any help,

    Th.

    Mit freundlichen Grüßen / Kind regards,
    Dr. Thomas Fox

    Boehringer Ingelheim Pharma GmbH & Co. KG
    Medicinal Chemistry
    Tel.: +49 (7351) 54-7585
    Fax: +49 (7351) 83-7585
    mailto:thomas....@boehringer-ingelheim.com <mailto:%7bemail%7d>

    Pflichtangaben finden Sie unter:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland

    Mandatory information can be found at:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland


    Diese E-Mail ist vertraulich zu behandeln. Sie kann besonderem
    rechtlichem Schutz unterliegen. Wenn Sie nicht der richtige
    Adressat sind, senden Sie bitte diese E-Mail an den Absender
    zurück, löschen die eingegangene E-Mail und geben den Inhalt der
    E-Mail nicht weiter. Jegliche unbefugte Bearbeitung, Nutzung,
    Vervielfältigung oder Verbreitung ist verboten. / This e-mail is
    confidential and may also be legally privileged. If you are not
    the intended recipient please reply to sender, delete the e-mail
    and do not disclose its contents to any person. Any unauthorized
    review, use, disclosure, copying or distribution is strictly
    prohibited.

    *Von:*Greg Landrum [mailto:greg.land...@gmail.com]
    *Gesendet:* Dienstag, 17. Oktober 2017 12:40
    *An:* Fox,Dr.,Thomas (RES MedChem) BIP-DE-B;
    rdkit-discuss@lists.sourceforge.net
    <mailto:rdkit-discuss@lists.sourceforge.net>
    *Betreff:* Re: [Rdkit-discuss] GetAlignmentTransform

    I’m glad you were able to track that down, it’s an interesting one.

    I’ll have to look, but we may be able to fix that on the C++ side.

    ------------------------------------------------------------------------

    *From:*thomas....@boehringer-ingelheim.com
    <mailto:thomas....@boehringer-ingelheim.com>
    <thomas....@boehringer-ingelheim.com
    <mailto:thomas....@boehringer-ingelheim.com>>
    *Sent:* Tuesday, October 17, 2017 2:27:39 AM
    *To:* rdkit-discuss@lists.sourceforge.net
    <mailto:rdkit-discuss@lists.sourceforge.net>
    *Subject:* Re: [Rdkit-discuss] GetAlignmentTransform

    Ok, mystery solved…argsort returns (at least on my Linux box) an
    int64, which GetAlignmentTransform obviously cant handle.

    Best,

    Th.

    Mit freundlichen Grüßen / Kind regards,
    Dr. Thomas Fox

    Boehringer Ingelheim Pharma GmbH & Co. KG
    Medicinal Chemistry
    Tel.: +49 (7351) 54-7585
    Fax: +49 (7351) 83-7585
    mailto:thomas....@boehringer-ingelheim.com <mailto:%7bemail%7d>

    Pflichtangaben finden Sie unter:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland

    Mandatory information can be found at:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland


    Diese E-Mail ist vertraulich zu behandeln. Sie kann besonderem
    rechtlichem Schutz unterliegen. Wenn Sie nicht der richtige
    Adressat sind, senden Sie bitte diese E-Mail an den Absender
    zurück, löschen die eingegangene E-Mail und geben den Inhalt der
    E-Mail nicht weiter. Jegliche unbefugte Bearbeitung, Nutzung,
    Vervielfältigung oder Verbreitung ist verboten. / This e-mail is
    confidential and may also be legally privileged. If you are not
    the intended recipient please reply to sender, delete the e-mail
    and do not disclose its contents to any person. Any unauthorized
    review, use, disclosure, copying or distribution is strictly
    prohibited.

    *Von:*thomas....@boehringer-ingelheim.com
    <mailto:thomas....@boehringer-ingelheim.com>
    [mailto:thomas....@boehringer-ingelheim.com]
    *Gesendet:* Montag, 16. Oktober 2017 16:40
    *An:* rdkit-discuss@lists.sourceforge.net
    <mailto:rdkit-discuss@lists.sourceforge.net>
    *Betreff:* [Rdkit-discuss] GetAlignmentTransform

    Hi,

    I have a weird problem with the GetAlignmentTransform function
    when using the atomMap argument. Depending how I create the
    underlying tuples and pass them via zip into the function call, I
    do get back the transformation matrix or the error message “cannot
    extract desired type from sequence”.

    As you can see in the attached python code snippet, I either
    collect the atom mappings (= atom ids) from  the distance matrix
    and argsort, by generating two lists and transforming them into
    two tuples, or by explicitly setting the tuples. Then I use zip to
    generate the mappings.

    In the latter two cases, things work fine, in the first case they
    don’t. To me, the tuples and the list(zip()) look identical, so I
    do not have an idea why GetAlignmentTransform throws up.

    I have attached two molecule files (essentially benzene and
    pyridine), the python code test.py and the output test.out

    I would be very grateful if anybody could shed some light on this
    and explain what I do wrong.

    Best,

    Th.

    Mit freundlichen Grüßen / Kind regards,
    Dr. Thomas Fox

    Boehringer Ingelheim Pharma GmbH & Co. KG
    Medicinal Chemistry
    Tel.: +49 (7351) 54-7585
    Fax: +49 (7351) 83-7585
    mailto:thomas....@boehringer-ingelheim.com <mailto:%7bemail%7d>

    Pflichtangaben finden Sie unter:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland

    Mandatory information can be found at:
    
https://www.boehringer-ingelheim.de/unser-unternehmen/gesellschaften-in-deutschland


    Diese E-Mail ist vertraulich zu behandeln. Sie kann besonderem
    rechtlichem Schutz unterliegen. Wenn Sie nicht der richtige
    Adressat sind, senden Sie bitte diese E-Mail an den Absender
    zurück, löschen die eingegangene E-Mail und geben den Inhalt der
    E-Mail nicht weiter. Jegliche unbefugte Bearbeitung, Nutzung,
    Vervielfältigung oder Verbreitung ist verboten. / This e-mail is
    confidential and may also be legally privileged. If you are not
    the intended recipient please reply to sender, delete the e-mail
    and do not disclose its contents to any person. Any unauthorized
    review, use, disclosure, copying or distribution is strictly
    prohibited.




    
------------------------------------------------------------------------------

    Check out the vibrant tech community on one of the world's most

    engaging tech sites, Slashdot.org!http://sdm.link/slashdot




    _______________________________________________

    Rdkit-discuss mailing list

    Rdkit-discuss@lists.sourceforge.net
    <mailto:Rdkit-discuss@lists.sourceforge.net>

    https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to