[Tutor] Problem with Spyder IDE in Anaconda3

2017-02-27 Thread Stephen P. Molnar

I had sent the following message to Anaconda Support:

I have just installed anaconda3-4.3.0 and upgraded Spyder to v-3.1.3.

When I open Spyder and run a python script that has run perfectly in a 
previous  version of Spyder I get the results that I expect,but with 
'Kernel died, restarting' and I get a new iPython console prompt. Also a 
popup that asks 'Do  you want to close this console?'.  If I answer 'No' 
I get the following in the Internal Console:



Spyder Internal Console

This console is used to report application
internal errors and to inspect Spyder
internals with the following commands:
  spy.app, spy.window, dir(spy)

Please don't use it to run your code

>>> WARNING:traitlets:kernel restarted
Traceback (most recent call last):
  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/base_frontend_mixin.py", 
line 163, in _dispatch

handler(msg)
  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.py", 
line 192, in _handle_execute_reply

super(NamepaceBrowserWidget, self)._handle_execute_reply(msg)
  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/jupyter_widget.py", 
line 184, in _handle_execute_reply

super(JupyterWidget, self)._handle_execute_reply(msg)
  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/frontend_widget.py", 
line 492, in _handle_execute_reply

self._request_info['execute'].pop(msg_id)
KeyError: '50af986d-2e5c-4cef-aef4-827370619c86'

Very strange, and most annoying.

I received an answer:

I know a solution for this problem. I guess you are using Kaspersky 
product. You need to add "python.exe", and "pythonw.exe" of Anaconda 
specific into Exclusions list and make them trusted applications.



Where would I find such a list?  There is no mention of such a list in 
the Debian Handbook and a Google search didn't find anything that I 
could see would apply to solution to this problem.  Nothing I found 
about the Kaspersky product told me where (or how) to find an exclusion 
list.


I'm hoping that kind sole on this list can help em solve this problem.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with Spyder IDE in Anaconda3

2017-02-27 Thread Stephen P. Molnar

On 02/27/2017 02:29 PM, Marc Tompkins wrote:

On Mon, Feb 27, 2017 at 10:46 AM, Stephen P. Molnar
mailto:s.mol...@sbcglobal.net>> wrote:

I had sent the following message to Anaconda Support:

I have just installed anaconda3-4.3.0 and upgraded Spyder to v-3.1.3.

When I open Spyder and run a python script that has run perfectly in
a previous  version of Spyder I get the results that I expect,but
with 'Kernel died, restarting' and I get a new iPython console
prompt. Also a popup that asks 'Do  you want to close this
console?'.  If I answer 'No' I get the following in the Internal
Console:


Spyder Internal Console

This console is used to report application
internal errors and to inspect Spyder
internals with the following commands:
   spy.app, spy.window, dir(spy)

Please don't use it to run your code

 >>> WARNING:traitlets:kernel restarted
Traceback (most recent call last):
   File

"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/base_frontend_mixin.py",
line 163, in _dispatch
 handler(msg)
   File

"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.py",
line 192, in _handle_execute_reply
 super(NamepaceBrowserWidget, self)._handle_execute_reply(msg)
   File

"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/jupyter_widget.py",
line 184, in _handle_execute_reply
 super(JupyterWidget, self)._handle_execute_reply(msg)
   File

"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/qtconsole/frontend_widget.py",
line 492, in _handle_execute_reply
 self._request_info['execute'].pop(msg_id)
KeyError: '50af986d-2e5c-4cef-aef4-827370619c86'

Very strange, and most annoying.

I received an answer:

I know a solution for this problem. I guess you are using Kaspersky
product. You need to add "python.exe", and "pythonw.exe" of Anaconda
specific into Exclusions list and make them trusted applications.


Where would I find such a list?  There is no mention of such a list
in the Debian Handbook and a Google search didn't find anything that
I could see would apply to solution to this problem.  Nothing I
found about the Kaspersky product told me where (or how) to find an
exclusion list.


With the usual caveats that your question isn't Python-specific, here's
the page from Kaspersky's website on how to create exclusions:
https://support.kaspersky.com/2695#block2

But: are you actually running Kaspersky Antivirus on a Debian machine?
Nothing wrong with that if so, but it's pretty unusual.  If not, then
you need to push the Anaconda people a bit harder for ideas.



To the best of my knowledge I am not running any anti-virus software. 
This has always been a Linux computer and there has been no need.


In fact, this has only happened since I had to reinstall Debian v8.5 and 
all of the upgrades.


--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Spyder IDE Anaconda3: Problem with Plt.savefig

2017-03-01 Thread Stephen P. Molnar
I have written a Python3 program to plot and save UV/VIS spectra from 
the results of an Orca quantum mechanical calculation.


I input the name of the molecule .dat file, without the suffix.

Everything is fine until I get to the point where I want to save the 
figure as name.png using:


figure = name+'.png'
print(figure)
plt.savefig('figure', bbox_inches='tight')

where the print statement verifies the nae of the saved figure. The 
problem is that the saved file is figure.png.


Unfortunately, as I am a neophyte to Python programming I don't what I 
am doing wrong.  It's probably a red-faced forehead slapper of a mistake 
on my part.


A point in the right direction to properly naming the saved figure will 
be muck appreciated.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Spyder IDE Anaconda3: Problem with Plt.savefig

2017-03-02 Thread Stephen P. Molnar

On 03/01/2017 08:32 PM, Alan Gauld via Tutor wrote:

On 01/03/17 20:20, Stephen P. Molnar wrote:

I have written a Python3 program to plot and save UV/VIS spectra from
the results of an Orca quantum mechanical calculation.


Caveat: This forum is for help on the core Python language
and its standard library. Asking about anything beyond that
may require a lot more information about the context - for
example few of us will know anything about UV/VIS spectra
(even what that means!)

However, I'll hazard a guess...


figure = name+'.png'
print(figure)
plt.savefig('figure', bbox_inches='tight')


Shouldn't the last line use the variable figure
rather than a literal string 'figure' :

plt.savefig(figure, bbox_inches='tight')


where the print statement verifies the nae of the saved figure. The
problem is that the saved file is figure.png.


I'm guessing that's because you are passing the string 'figure'
instead of the variable.

But I don;t know anything about your plt object
or its savefig() method, not even which library
you are using. Is it matplotlib? Or something else?

HTH



That was the problem.

Many thanks.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Extract Block of Data from a 2D Array

2017-03-31 Thread Stephen P. Molnar

I have a block of data extracted from a quantum mechanical calculation:

CARTESIAN COORDINATES (A.U.)

  NO LB  ZAFRAG MASS X   Y   Z
   0 C 6.012.011   -3.2656360.1988940.090858
   1 C 6.012.011   -1.3071611.5222121.003463
   2 C 6.012.0111.2133360.948208   -0.033373
   3 N 7.014.0073.2386501.0415231.301322
   4 C 6.012.011   -5.9544890.6508780.803379
   5 C 6.012.0115.6544760.4800660.013757

where the number of lines depends upon the molecule being considered.

I want to extract the block of data starting on line 4 and column 4. 
Unfortunately, the only programming language in which I used to be 
competent in is Fortran.  I have attempted researching this problem, but 
have only succeeded in increasing my mental entropy.


Help will be much appreciated.  Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extract Block of Data from a 2D Array

2017-03-31 Thread Stephen P. Molnar

On 03/31/2017 10:29 AM, Alan Gauld via Tutor wrote:

On 31/03/17 13:19, Stephen P. Molnar wrote:

I have a block of data extracted from a quantum mechanical calculation:


How is this data stored? On paper? In a database? In XML? A CSV file?
Plain text? The answer to that will go a long way to pointing you in the
right direction for a solution.


CARTESIAN COORDINATES (A.U.)

NO LB  ZAFRAG MASS X   Y   Z
 0 C 6.012.011   -3.2656360.1988940.090858
 1 C 6.012.011   -1.3071611.5222121.003463
 2 C 6.012.0111.2133360.948208   -0.033373
 3 N 7.014.0073.2386501.0415231.301322
 4 C 6.012.011   -5.9544890.6508780.803379
 5 C 6.012.0115.6544760.4800660.013757

where the number of lines depends upon the molecule being considered.

I want to extract the block of data starting on line 4 and column 4.


A block of data needs a start and end. Where is the end?
Also which of the above lines is line 4?
I'd read it as the one starting the actual raw data values.
But it could be the 4th line of values that you want?

It might help to know the OS you are using too because Unix
in particular has some OS level tools that might simplify
preparing the data.



Sorry about the omission.  The data is in a tab separated file.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extract Block of Data from a 2D Array

2017-03-31 Thread Stephen P. Molnar

On 03/31/2017 10:50 AM, Peter Otten wrote:

Stephen P. Molnar wrote:


I have a block of data extracted from a quantum mechanical calculation:

CARTESIAN COORDINATES (A.U.)

NO LB  ZAFRAG MASS X   Y   Z
 0 C 6.012.011   -3.2656360.1988940.090858
 1 C 6.012.011   -1.3071611.5222121.003463
 2 C 6.012.0111.2133360.948208   -0.033373
 3 N 7.014.0073.2386501.0415231.301322
 4 C 6.012.011   -5.9544890.6508780.803379
 5 C 6.012.0115.6544760.4800660.013757

where the number of lines depends upon the molecule being considered.

I want to extract the block of data starting on line 4 and column 4.
Unfortunately, the only programming language in which I used to be
competent in is Fortran.  I have attempted researching this problem, but
have only succeeded in increasing my mental entropy.

Help will be much appreciated.  Thanks in advance.



pandas is the swiss army knife of data manipulation in Python -- albeit with
a non-negligable learning curve. Some examples (from an amateur):

$ cat data.txt
CARTESIAN COORDINATES (A.U.)

NO LB  ZAFRAG MASS X   Y   Z
 0 C 6.012.011   -3.2656360.1988940.090858
 1 C 6.012.011   -1.3071611.5222121.003463
 2 C 6.012.0111.2133360.948208   -0.033373
 3 N 7.014.0073.2386501.0415231.301322
 4 C 6.012.011   -5.9544890.6508780.803379
 5 C 6.012.0115.6544760.4800660.013757
$ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

import pandas
table = pandas.read_table("data.txt", skiprows=2, delimiter=" ",

skipinitialspace=True)

table

NO LB  ZA  FRAGMASS X Y Z
0   0  C   6 0  12.011 -3.265636  0.198894  0.090858
1   1  C   6 0  12.011 -1.307161  1.522212  1.003463
2   2  C   6 0  12.011  1.213336  0.948208 -0.033373
3   3  N   7 0  14.007  3.238650  1.041523  1.301322
4   4  C   6 0  12.011 -5.954489  0.650878  0.803379
5   5  C   6 0  12.011  5.654476  0.480066  0.013757

[6 rows x 8 columns]

table[3:]

NO LB  ZA  FRAGMASS X Y Z
3   3  N   7 0  14.007  3.238650  1.041523  1.301322
4   4  C   6 0  12.011 -5.954489  0.650878  0.803379
5   5  C   6 0  12.011  5.654476  0.480066  0.013757

[3 rows x 8 columns]

table[["X", "Y", "Z"]]

   X Y Z
0 -3.265636  0.198894  0.090858
1 -1.307161  1.522212  1.003463
2  1.213336  0.948208 -0.033373
3  3.238650  1.041523  1.301322
4 -5.954489  0.650878  0.803379
5  5.654476  0.480066  0.013757

[6 rows x 3 columns]

table.MASS.mean()

12.343


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Problem solved!

Many thanks.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Euclidean Distances between Atoms in a Molecule.

2017-04-02 Thread Stephen P. Molnar
I am trying to port a program that I wrote in FORTRAN twenty years ago 
into Python 3 and am having a hard time trying to calculate the 
Euclidean distance between each atom in the molecule and every other 
atom in the molecule.


Here is a typical table of coordinates:


  MASS X Y Z
0   12.011 -3.265636  0.198894  0.090858
1   12.011 -1.307161  1.522212  1.003463
2   12.011  1.213336  0.948208 -0.033373
3   14.007  3.238650  1.041523  1.301322
4   12.011 -5.954489  0.650878  0.803379
5   12.011  5.654476  0.480066  0.013757
6   12.011  6.372043  2.731713 -1.662411
7   12.011  7.655753  0.168393  2.096802
8   12.011  5.563051 -1.990203 -1.511875
91.008 -2.939469 -1.327967 -1.247635
10   1.008 -1.460475  2.993912  2.415410
11   1.008  1.218042  0.451815 -2.057439
12   1.008 -6.255901  2.575035  1.496984
13   1.008 -6.560562 -0.695722  2.248982
14   1.008 -7.152500  0.390758 -0.864115
15   1.008  4.959548  3.061356 -3.139100
16   1.008  8.197613  2.429073 -2.588339
17   1.008  6.503322  4.471092 -0.543939
18   1.008  7.845274  1.892126  3.227577
19   1.008  9.512371 -0.273198  1.291080
20   1.008  7.147039 -1.365346  3.393778
21   1.008  4.191488 -1.928466 -3.057804
22   1.008  5.061650 -3.595015 -0.302810
23   1.008  7.402586 -2.392148 -2.374554

What I need for further calculation is a matrix of the Euclidean 
distances between the atoms.


So far in searching the Python literature I have only managed to confuse 
myself and would greatly appreciate any pointers towards a solution.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Euclidean Distances between Atoms in a Molecule.

2017-04-03 Thread Stephen P. Molnar

On 04/03/2017 05:36 AM, Peter Otten wrote:

Stephen P. Molnar wrote:


I am trying to port a program that I wrote in FORTRAN twenty years ago
into Python 3 and am having a hard time trying to calculate the
Euclidean distance between each atom in the molecule and every other
atom in the molecule.

Here is a typical table of coordinates:


MASS X Y Z
0   12.011 -3.265636  0.198894  0.090858
1   12.011 -1.307161  1.522212  1.003463
2   12.011  1.213336  0.948208 -0.033373
3   14.007  3.238650  1.041523  1.301322
4   12.011 -5.954489  0.650878  0.803379
5   12.011  5.654476  0.480066  0.013757
6   12.011  6.372043  2.731713 -1.662411
7   12.011  7.655753  0.168393  2.096802
8   12.011  5.563051 -1.990203 -1.511875
91.008 -2.939469 -1.327967 -1.247635
10   1.008 -1.460475  2.993912  2.415410
11   1.008  1.218042  0.451815 -2.057439
12   1.008 -6.255901  2.575035  1.496984
13   1.008 -6.560562 -0.695722  2.248982
14   1.008 -7.152500  0.390758 -0.864115
15   1.008  4.959548  3.061356 -3.139100
16   1.008  8.197613  2.429073 -2.588339
17   1.008  6.503322  4.471092 -0.543939
18   1.008  7.845274  1.892126  3.227577
19   1.008  9.512371 -0.273198  1.291080
20   1.008  7.147039 -1.365346  3.393778
21   1.008  4.191488 -1.928466 -3.057804
22   1.008  5.061650 -3.595015 -0.302810
23   1.008  7.402586 -2.392148 -2.374554

What I need for further calculation is a matrix of the Euclidean
distances between the atoms.

So far in searching the Python literature I have only managed to confuse
myself and would greatly appreciate any pointers towards a solution.

Thanks in advance.



Stitched together with heavy use of a search engine:

$ cat data.txt
MASS X Y Z
0   12.011 -3.265636  0.198894  0.090858
1   12.011 -1.307161  1.522212  1.003463
2   12.011  1.213336  0.948208 -0.033373
3   14.007  3.238650  1.041523  1.301322
4   12.011 -5.954489  0.650878  0.803379
5   12.011  5.654476  0.480066  0.013757
6   12.011  6.372043  2.731713 -1.662411
7   12.011  7.655753  0.168393  2.096802
8   12.011  5.563051 -1.990203 -1.511875
91.008 -2.939469 -1.327967 -1.247635
10   1.008 -1.460475  2.993912  2.415410
11   1.008  1.218042  0.451815 -2.057439
12   1.008 -6.255901  2.575035  1.496984
13   1.008 -6.560562 -0.695722  2.248982
14   1.008 -7.152500  0.390758 -0.864115
15   1.008  4.959548  3.061356 -3.139100
16   1.008  8.197613  2.429073 -2.588339
17   1.008  6.503322  4.471092 -0.543939
18   1.008  7.845274  1.892126  3.227577
19   1.008  9.512371 -0.273198  1.291080
20   1.008  7.147039 -1.365346  3.393778
21   1.008  4.191488 -1.928466 -3.057804
22   1.008  5.061650 -3.595015 -0.302810
23   1.008  7.402586 -2.392148 -2.374554
$ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

import numpy, pandas, scipy.spatial.distance as dist
df = pandas.read_table("data.txt", sep=" ", skipinitialspace=True)
a = numpy.array(df[["X", "Y", "Z"]])
dist.squareform(dist.pdist(a, "euclidean"))



Here's an example with just the first 4 atoms:


dist.squareform(dist.pdist(a[:4], "euclidean"))

array([[ 0.,  2.53370139,  4.54291701,  6.6694065 ],
[ 2.53370139,  0.,  2.78521357,  4.58084922],
[ 4.54291701,  2.78521357,  0.,  2.42734737],
[ 6.6694065 ,  4.58084922,  2.42734737,  0.]])

See
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html
There may be a way to do this with pandas.pivot_table(), but I didn't manage
to find that.

As Alan says, this is not the appropriate forum for the topic you are
belabouring.

Work your way through a Python tutorial to pick up the basics (we can help
you with this), then go straight to where the (numpy/scipy) experts are.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Thanks to everyone who answered.

The problem has been solved.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 3.6 Multiply the elements of a 2D Array by the elements of a 1D Aeeay

2017-04-13 Thread Stephen P. Molnar
I am attempting to port a program that I wrote about 20 years ago from 
FORTRAN to Python.  So far, I have bumbled my way to the point that I 
can get all of the input data resulting from a quantum mechanical 
calculation of a very simple organic molecule in to a Python program, 
but am encountering problems with processing the data.


I have an list generated by:   s = np.linspace(start,finish,points)

and an array D:

 [ 0.  2.0598013.60937686  3.32591826  2.81569212]
 [ 2.0598010.  4.71452879  4.45776445  4.00467382]
 [ 3.60937686  4.71452879  0.  5.66500917  5.26602175]
 [ 3.32591826  4.45776445  5.66500917  0.  5.02324896]
 [ 2.81569212  4.00467382  5.26602175  5.02324896  0.]

Now I can multiply the Array by one element of the list:

s2 = 1.100334448160535050  (The first non-zero list element.)
s2_D = s2*np.array(D)

which results in:

 [ 0.  2.26647 3.97152169  3.65962243  3.09820303]
 [ 2.26647 0.  5.18755844  4.90503178  4.40648056]
 [ 3.97152169  5.18755844  0.  6.23340474  5.79438514]
 [ 3.65962243  4.90503178  6.23340474  0.  5.52725387]
 [ 3.09820303  4.40648056  5.79438514  5.52725387  0.]

I checked this, rather laboriously, in a spreadsheet.

However, what I want to do is multiply each element ob D by each element 
of s and sum all of the products.


I have Goggled quite a bit, but have not found anything too awfully useful.

Any pointers in the right direction will be much appreciated.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.6 Multiply the elements of a 2D Array by the elements of a 1D Aeeay

2017-04-14 Thread Stephen P. Molnar

On 04/14/2017 04:21 AM, Peter Otten wrote:

Stephen P. Molnar wrote:


However, what I want to do is multiply each element ob D by each element
of s and sum all of the products.


If you *really* want this:

sum_of_all_products = s.sum() * D.sum()

example:

s = [a b c]

D = [[a1 a2]
  [a3 a4]]

a*a1 + a*a2 + a*a3 + a*a4 = a * D.sum()

d := D.sum()
a*d + b*d + c*d = s.sum() * d

Even if that's what you want you should heed Steven's advice.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Thanks for the replies to my message.

First of all, allow me to apologize for the imprecise nature of my request.

Then I want t assure everyone that I am not asking someone else to write 
a program for me, I am not a student with a homework problem.


Rather as I wrote in my email I am attempting to port a program from 
FORTRAN to Python.


The equation that I a want to evaluate (the one that I programmed in 
FORTRAN) is equation (7) in the attached scan of one of the pages of


Stephen P. Molnar and James W. King, Theory and Applications of the 
Integrated Molecular Transform and the Normalized Molecular Moment 
Structure Descriptors: QSAR and QSPR Paradigms, Int. J Quantum Chem., 
85, 662 (2001).


What I have managed to do so far is:

import numpy as np
import numpy, pandas, scipy.spatial.distance as dist


start=1
finish=31
points=300
s = np.linspace(start,finish,points) #300 points between 1.0 and 31.0

name = input("Enter Molecule ID: ")
name = str(name)
name_in = name+'.dat'

df = pandas.read_table(name_in, skiprows=2, sep=" ", 
skipinitialspace=True)

mass_data = numpy.array(df["MASS"])
print('MASS = ',mass_data)
N =  numpy.ma.size(mass_data)
a = numpy.array(df[["X", "Y", "Z"]])
dist.squareform(dist.pdist(a, "euclidean"))
anrows, ancols = np.shape(a)
a_new = a.reshape(anrows, 1, ancols)
diff = a_new - a

D = (diff ** 2).sum(2)
D = np.sqrt(D)

df = pandas.read_table(name_in, skiprows=2, sep=" ", 
skipinitialspace=True)

mass_data = numpy.array(df["MASS"])
print('MASS = ',mass_data)
N =  numpy.ma.size(mass_data)
a = numpy.array(df[["X", "Y", "Z"]])
dist.squareform(dist.pdist(a, "euclidean"))
anrows, ancols = np.shape(a)
a_new = a.reshape(anrows, 1, ancols)
diff = a_new - a

D = (diff ** 2).sum(2)
D = np.sqrt(D)
print(D)

for i in range(numpy.ma.size(mass_data)):
for j in range(0, N-1):
for k in range(j+1,N):
print(D[j,k])

np.savetxt('D(ij)',D,delimiter=' ')

for k in range(0, N-1):

for k in range(k+1,N):
A = (mass_data[j]*mass_data[k])

Now, the problem with which I am struggling is the evaluation of the s 
times the r_sub_i_sub_j term.  This should result in 300 floating point 
numbers between 1.0 and 31.0.


I hope that I have eliminated the confusion at this point.

This is, of course, not the end point of my modeling, but what I feel is 
an important result in QSAR studies.


I will be very appreciative of help at this point.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.6 Multiply the elements of a 2D Array by the elements of a 1D Aeeay

2017-04-14 Thread Stephen P. Molnar

On 04/14/2017 01:11 PM, Alan Gauld via Tutor wrote:

On 14/04/17 13:41, Stephen P. Molnar wrote:


The equation that I a want to evaluate (the one that I programmed in
FORTRAN) is equation (7) in the attached scan of one of the pages of

Stephen P. Molnar and James W. King, Theory and Applications of the
Integrated Molecular Transform and the Normalized Molecular Moment
Structure Descriptors: QSAR and QSPR Paradigms, Int. J Quantum Chem.,
85, 662 (2001).


The problem is that you are asking quite technical questions on a
list aimed at beginners to both programming and the Python language. I'd
estimate that only about 10-20% of the readership have
a math/science background of the depth required for your issues.
And a similar few will be familiar with numpy which is not part
of the standard library (although to confuse things there are
Python distros like Anaconda that do include the SciPy stuff,
but the standard library as described on python.org does not.)

As has already been suggested you would get a much higher hit
rate by asking on the SciPy/Numpy support fora:

https://scipy.org/scipylib/mailing-lists.html

On those lists more like 90% of the readers will be in a position
to understand your issues and they will be experienced in using
SciPy and numpy. There is a very good chance that someone there
will understand what the problem is and have already solved it.

We are very happy to answer questions about the core language
and libraries but detailed Numpy stuff really is beyond the
scope of this list.



I appreciate the suggestion of the SciPy Mailing List.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.6 Multiply the elements of a 2D Array by the elements of a 1D Aeeay

2017-04-17 Thread Stephen P. Molnar

On 04/16/2017 04:57 PM, Sergio Rojas wrote:


On 04/14/2017 04:21 AM, Peter Otten wrote:

Stephen P. Molnar wrote:


However, what I want to do is multiply each element ob D by each element
of s and sum all of the products.


If you *really* want this:

sum_of_all_products = s.sum() * D.sum()

example:

s = [a b c]

D = [[a1 a2]
[a3 a4]]

a*a1 + a*a2 + a*a3 + a*a4 = a * D.sum()

d := D.sum()
a*d + b*d + c*d = s.sum() * d

Even if that's what you want you should heed Steven's advice.



Nice example on "analyze before computing". Nevertheless,
A lazy man's approach to life might  go  using numpy ufunc.outer
  [ https://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.outer.html 
]


In [1]: import numpy as np

In [2]: from sympy import symbols

In [3]: x1, y1, z1, x2, y2, z2, x3, y3, z3 = symbols('x1 y1 z1 x2 y2 z2 x3 y3 z3
...: ')

In [4]: x=np.array([[x1,y1,z1], [x2,y2,z2], [x3,y3,z3]])

In [5]: z=np.array([z1,z2,z3])

In [6]: print(np.multiply.outer(z,x))
[[[x1*z1 y1*z1 z1**2]
   [x2*z1 y2*z1 z1*z2]
   [x3*z1 y3*z1 z1*z3]]

  [[x1*z2 y1*z2 z1*z2]
   [x2*z2 y2*z2 z2**2]
   [x3*z2 y3*z2 z2*z3]]

  [[x1*z3 y1*z3 z1*z3]
   [x2*z3 y2*z3 z2*z3]
   [x3*z3 y3*z3 z3**2]]]

In [7]: np.multiply.outer(z,x).sum()
Out[7]: x1*z1 + x1*z2 + x1*z3 + x2*z1 + x2*z2 + x2*z3 + x3*z1 + x3*z2 + x3*z3 + 
y1*z1 + y1*z2 + y1*z3 + y2*z1 + y2*z2 + y2*z3 + y3*z1 + y3*z2 + y3*z3 + z1**2 + 
2*z1*z2 + 2*z1*z3 + z2**2 + 2*z2*z3 + z3**2

In [8]:

Sergio
https://www.packtpub.com/big-data-and-business-intelligence/numerical-and-scientific-computing-scipy-video
https://github.com/rojassergio/Learning-Scipy
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Thanks for the reply.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 3.6 Extract Floating Point Data from a Text File

2017-04-30 Thread Stephen P. Molnar


I am using the Spyder v-3.1.2 IDE and porting a FORTRAN program that I 
wrote about 20 years ago to Python  Unfortunately, I am very much a 
novice in Python .


I would have managed to extract input data from another calculation (not 
a Python program) into the following text file.


LOEWDIN ATOMIC CHARGES
 --
0 C :   -0.780631
1 H :0.114577
2 Br:0.309802
3 Cl:0.357316
4 F :   -0.001065

What I need to do is extract the floating point numbers into a Python file

What I need to do is extract the floating point numbers into a Python file.

Googling the problem has not resulted on any insight as to the solution, 
and any help will be much appreciated.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.6 Extract Floating Point Data from a Text File

2017-04-30 Thread Stephen P. Molnar

On 04/30/2017 02:02 PM, Steven D'Aprano wrote:

On Sun, Apr 30, 2017 at 06:09:12AM -0400, Stephen P. Molnar wrote:
[...]

I would have managed to extract input data from another calculation (not
a Python program) into the following text file.

LOEWDIN ATOMIC CHARGES
  --
 0 C :   -0.780631
 1 H :0.114577
 2 Br:0.309802
 3 Cl:0.357316
 4 F :   -0.001065

What I need to do is extract the floating point numbers into a Python file


I don't quite understand your question, but I'll take a guess. I'm going
to assume you have a TEXT file containing literally this text:

#  cut here 

LOEWDIN ATOMIC CHARGES
--
0 C :   -0.780631
1 H :0.114577
2 Br:0.309802
3 Cl:0.357316
4 F :   -0.001065

#  cut here 


and you want to extract the atomic symbols (C, H, Br, Cl, F) and
charges as floats. For the sake of the exercise, I'll extract them into
a dictionary {'C': -0.780631, 'H': 0.114577, ... } then print them.

Let me start by preparing the text file. Of course I could just use a
text editor, but let's do it with Python:


data = """LOEWDIN ATOMIC CHARGES
--
0 C :   -0.780631
1 H :0.114577
2 Br:0.309802
3 Cl:0.357316
4 F :   -0.001065
"""

filename = 'datafile.txt'
with open(filename, 'w') as f:
 f.write(data)


(Of course, in real life, it is silly to put your text into Python just
to write it out to a file so you can read it back in. But as a
programming exercise, its fine.)

Now let's re-read the file, processing each line, and extract the data
we want.

atomic_charges = {}
filename = 'datafile.txt'
with open(filename, 'r') as f:
 # Skip lines until we reach a line made of nothing but ---
 for line in f:
 line = line.strip()  # ignore leading and trailing whitespace
 if set(line) == set('-'):
 break
 # Continue reading lines from where we last got to.
 for line in f:
 line = line.strip()
 if line == '':
 # Skip blank lines.
 continue
 # We expect lines to look like:
 #   1 C :   0.12345
 # where there may or may not be a space between the
 # letter and the colon. That makes it tricky to process,
 # so let's force there to always be at least one space.
 line = line.replace(':', ' :')
 # Split on spaces.
 try:
 number, symbol, colon, number = line.split()
 except ValueError as err:
 print("failed to process line:", line)
 print(err)
 continue  # skip to the next line
 assert colon == ':', 'expected a colon but found something else'
 try:
 number = float(number)
 except ValueError:
 # We expected a numeric string like -0.234 or 0.123, but got
 # something else. We could skip this line, or replace it
 # with an out-of-bounds value. I'm going to use an IEEE-754
 # "Not A Number" value as the out-of-bounds value.
 number = float("NaN")
 atomic_charges[symbol] = number

# Finished! Let's see what we have:
for sym in sorted(atomic_charges):
 print(sym, atomic_charges[sym])





There may be more efficient ways to process the lines, for example by
using a regular expression. But its late, and I'm too tired to go
messing about with regular expressions now. Perhaps somebody else will
suggest one.




Steve

Thanks for your reply to my, unfortunately imprecisely worded, question.

Here are the results of applying you code to my data:

Br 0.309802
C -0.780631
Cl 0.357316
F -0.001065
H 0.114577

I should have mentioned that I already have the file, it's part if the 
output from the Orca Quantum Chemistry Program.


As soon as I understand teh code I'm going to have to get rid of the 
atomic symbols and get the charges in the same order as they are in the 
original LOEWDIN ATOMIC CHARGES file.  The Molecular Transform suite of 
programs depends on the distances between pairs of bonded atoms, hence 
the order is important.


Again, many thanks for your help.

Regards,

Steve

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Index Out of Range?List

2017-05-03 Thread Stephen P. Molnar
I have a section of Python 3 code that is intended to be part of a 
larger program which essentially inputs the file:


LOEWDIN ATOMIC CHARGES
--
   0 C :   -0.780631
   1 H :0.114577
   2 Br:0.309802
   3 Cl:0.357316
   4 F :   -0.001065

The code is:

import numpy as np


name = input("Enter Molecule ID: ")
name = str(name)

name_in =name[:]+'.lac.dat'
print(name_in)

atm_chg = []
"""
atm_chg = open(name_in,'r')
for line in atm_chg:
print(line, end=' ')
"""
#all_contents = []
with open(name_in) as f:
# skip two lines
f.readline()
f.readline()
for line in f.readlines():
atm_chg.append(float( line.split()[-1] ))

p.asarray({atm_chg})

When it is run I get:

IndexError: list index out of range

However, the Variable Explorer shows:

 [-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]

One line of which is exactly what I want as input to the next step in 
the larger calculation.


Now, my question is how do I extract just one line of this file?

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Index Out of Range?List

2017-05-04 Thread Stephen P. Molnar

On 05/03/2017 08:32 PM, Steven D'Aprano wrote:

On Wed, May 03, 2017 at 07:32:53PM -0400, Stephen P. Molnar wrote:

[...]

When it is run I get:

IndexError: list index out of range


That alone is useless to us. Please post the full traceback, starting
from the line

 Traceback (most recent call last):

Among other things, it will show us the line of code that causes the
error. Otherwise, we're just guessing.

You might also like to consider a simple debugging technique: print
the index and the length of the list just before trying to use them.
E.g. if you want to extract the nth item of a list, write:

 print(n, len(a_list))
 value = a_list[n]


(And yes, I completely agree that the error message should show that
information, but it currently doesn't.)



Thanks for the reply.

Here are the error messages:

Enter Molecule ID: A
A.lac.dat
Traceback (most recent call last):

  File "", line 1, in 
runfile('/home/comp/Apps/Python/Testing/ReadFile_1.py', 
wdir='/home/comp/Apps/Python/Testing')


  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 866, in runfile

execfile(filename, namespace)

  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 102, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/comp/Apps/Python/Testing/ReadFile_1.py", line 32, in 
    atm_chg.append(float( line.split()[-1] ))

IndexError: list index out of range

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Index Out of Range?List

2017-05-04 Thread Stephen P. Molnar

On 05/03/2017 08:51 PM, Alan Gauld via Tutor wrote:

On 04/05/17 00:32, Stephen P. Molnar wrote:


import numpy as np

name = input("Enter Molecule ID: ")
name = str(name)


You don't need the str(), input always returns a string.


name_in =name[:]+'.lac.dat'


And you don't need the [:]. Just use

name_in = name + '.lac.dat'


print(name_in)

atm_chg = []



"""
atm_chg = open(name_in,'r')
for line in atm_chg:
  print(line, end=' ')
"""

This creates a 3 line string which is not assigned to any object.
It is not executable code and will not be executed. Maybe you
are doing it as a way of commenting out a block? If so it would be
better in a post to just delete it, it just adds confusion
otherwise. (Well, it confused me! :-)


with open(name_in) as f:
  # skip two lines
  f.readline()
  f.readline()
  for line in f.readlines():
  atm_chg.append(float( line.split()[-1] ))

p.asarray({atm_chg})


Where did p come from?
Should it be np? asarray() sounds like it might be a numpy thing.
And I'm not sure what the {atm_chg} is supposed to do - create
a single element set using your list maybe? I get an "unhashable"
error if I try it at the >>>> prompt.


When it is run I get:

IndexError: list index out of range


I'm pretty sure you get more than that, please post the full
error text, it's much harder to diagnose problems with just
the summary.

Since the only indexing you do is in this line


  atm_chg.append(float( line.split()[-1] ))


I'll assume that's where the problem lies.
Try checking if the string is not empty before using it:

  for line in f.readlines():
  if line:
 atm_chg.append(float( line.split()[-1] ))



However, the Variable Explorer shows:


I have no idea what the Variable Explorer is?
Is it part of your IDE? Or of numpy?
If the IDE which IDE are you using?


   [-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]
[-0.780631, 0.114577, 0.309802, 0.357316, -0.001065]

One line of which is exactly what I want as input to the next step in
the larger calculation.

Now, my question is how do I extract just one line of this file?


Any particular line? And which file are you talking about?
The data should be in the list variable, atm_chg.
In which case the first line is therefore:  atm_chg[0]

Or you can process each line using the usual for loop:

for line in atm_chg:
 # use line here


Thanks for your reply.

The Variable Explorer is part of the Spyder IDE.

I have edited the code:

import numpy as np


name = input("Enter Molecule ID: ")
#name = str(name)

name_in =name[:]+'.lac.dat'
print(name_in)

atm_chg = []

with open(name_in) as f:
# skip two lines
f.readline()
f.readline()
for line in f.readlines():
atm_chg.append(float( line.split()[-1] ))


np.asarray({atm_chg})

Execution still generates the errors:

runfile('/home/comp/Apps/Python/Testing/ReadFile_2.py', 
wdir='/home/comp/Apps/Python/Testing')


Enter Molecule ID: A
A.lac.dat
Traceback (most recent call last):

  File "", line 1, in 
runfile('/home/comp/Apps/Python/Testing/ReadFile_2.py', 
wdir='/home/comp/Apps/Python/Testing')


  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 866, in runfile

execfile(filename, namespace)

  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 102, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/comp/Apps/Python/Testing/ReadFile_2.py", line 27, in 
atm_chg.append(float( line.split()[-1] ))

IndexError: list index out of range

from the input file:

runfile('/home/comp/Apps/Python/Testing/ReadFile_2.py', 
wdir='/home/comp/Apps/Python/Testing')


Enter Molecule ID: A
A.lac.dat
Traceback (most recent call last):

  File "", line 1, in 
runfile('/home/comp/Apps/Python/Testing/ReadFile_2.py', 
wdir='/home/comp/Apps/Python/Testing')


  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 866, in runfile

execfile(filename, namespace)

  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 102, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/comp/Apps/Python/Testing/ReadFile_2.py", line 27, in 
atm_chg.append(float( line.split()[-1] ))

IndexError: list index out of range

Finally, here is the code for which I need input data for the 
calculation of the Integrated Charge T

[Tutor] python 3 np.savetxt(name_s, I_z) produces IndexError: tuple index out of range

2017-05-11 Thread Stephen P. Molnar

 0
down vote
favorite


I am using Spyder3.1.4 with Python 3.6.0 | Anaconda 4.3.0 (64-bit) | and 
IPython 6.0.0.


My script is rather long and calculates a series of molecular indices 
using the same formula and a series of different coefficients. The 
script uses the np.savetxt() quite a few times, but one use generates 
the title error. The offending line is np.savetxt(name_s,I_z) where I_z 
is a single number of type float64 with a size of 1.


If I comment out the line containing the np.savetxt statement the script 
runs to completion and np.savetxt(name_s,I_oe) where I_oe is a float64 
number except it has a size of (1,).


Now, it would seems to me that the different size of the name in the 
np.savetxt statement causes the error, but how do I correct it? Google 
has not resulted in a solution.


Here is an abbreviated copy of the script:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  8 15:17:07 2017

@author: comp

Copyright (c) 2017 Stephen P. Molnar, Ph.D.

"""
import matplotlib.pyplot as plt
import numpy as np


start=1
finish=31
points=300

s = np.linspace(start, finish, points)
np.savetxt('s',s)

name = input("Enter Molecule ID: ")

name_in = name+'.dat'

dtype = [('NO', int), ('LB', 'S2'), ('ZA', float), ('FRAG', int),
 ('MASS', float), ('X', float), ('Y', float), ('Z', float)]
data = np.genfromtxt(name_in, dtype=dtype, skip_header=3)

N =  data.shape[0]
a = np.array([data['X'], data['Y'], data['Z']])
anrows, ancols = np.shape(a)
a_new = a.reshape(anrows, 1, ancols)

diff = a_new - a

D = (diff ** 2).sum(2)
D = np.sqrt(D)
r = D

def eq7(a, s, Z):
"""
Computes equation 7 in Molnar & King (2001)
"""
N = r.shape[0]
I = np.zeros(s.shape)
for i in range(1, N):
for j in range(i):
I += Z[i] * Z[j] * np.sin(s * r[i, j])/(s * r[i, j])

return I

I = eq7(r, s, data['ZA'])

name_s = name+'-Iz'
np.savetxt(name_s,I)

I_sq = []
I_sq = I**2
Area = []

name_s = name+'-Iz'

Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
I_z = np.sqrt(Area)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('Atomic Number Transform (FT$_z$)')
plt.show()
print('FTz: ',I_z)
name_s = name+'-FTz'
print(name_s)
np.savetxt(name_s,I_z)


#--
# MASS Mollecular Transform  FT_m


I = eq7(r, s, data['MASS'])

name_s = name+'-Im'

np.savetxt(name_s,I)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('MASS Transform (FT$_m$)')
plt.show()

I_sq = I**2
Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
np.savetxt('I_m',I,delimiter=' ')
I_m = np.sqrt([Area])

print('FTm: ',I_m)
name_s = name+'-FTm'
np.savetxt(name_s,I_m)

"""
#--

name_in = name+'.mpa.dat'

dtype_1 = [('NO', int), ('ATOM', 'S2'), ('NA', float), ('ZA', float),
 ('QA', float), ('VA', float), ('BVA', float), ('FA', float)]

data_1 = np.genfromtxt(name_in, dtype=dtype_1, skip_header=11)

qa = []
qa = np.array(data_1['QA'])
va = []
va = np.array([data_1['VA']])
bva =[]
bva = np.array([data_1['BVA']])
fa = []
fa = np.array([data_1['FA']])

#--
#Charge Molecular Transform  FT_c

I = eq7(r, s, data_1['QA'])
I_c = I

name_s = name+'-Ic'

np.savetxt(name_s,I)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('Charge Transform (FT$_C$)')
plt.show()

I_sq = I_c**2
Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
np.savetxt(name_s,I,delimiter=' ')
I_c = np.sqrt([Area])

print('FTc: ',I_c)
name_s = name+'-FTc'

np.savetxt(name_s,I_c)


"""

And here is the input file:

CARTESIAN COORDINATES (A.U.)
----
  NO LB  ZAFRAG MASS X   Y   Z
   0 C 6.012.0110.000.000.00
   1 H 1.0 1.0082.0598010.000.00
   2 Br   35.079.900   -1.2031263.4029530.00
   3 Cl   17.035.453   -1.108639   -1.5678532.715601
   4 F 9.018.998   -0.938564   -1.327330   -2.299003

The last line in the script is causing the problem.

A pointer towards the solution to the problem will be much apprecialted.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 3 np.savetxt(name_s, I_z) produces IndexError: tuple index out of range

2017-05-11 Thread Stephen P. Molnar

On 05/11/2017 02:26 PM, Stephen P. Molnar wrote:

  0
down vote
favorite


I am using Spyder3.1.4 with Python 3.6.0 | Anaconda 4.3.0 (64-bit) | and
IPython 6.0.0.

My script is rather long and calculates a series of molecular indices
using the same formula and a series of different coefficients. The
script uses the np.savetxt() quite a few times, but one use generates
the title error. The offending line is np.savetxt(name_s,I_z) where I_z
is a single number of type float64 with a size of 1.

If I comment out the line containing the np.savetxt statement the script
runs to completion and np.savetxt(name_s,I_oe) where I_oe is a float64
number except it has a size of (1,).

Now, it would seems to me that the different size of the name in the
np.savetxt statement causes the error, but how do I correct it? Google
has not resulted in a solution.

Here is an abbreviated copy of the script:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  8 15:17:07 2017

@author: comp

Copyright (c) 2017 Stephen P. Molnar, Ph.D.

"""
import matplotlib.pyplot as plt
import numpy as np


start=1
finish=31
points=300

s = np.linspace(start, finish, points)
np.savetxt('s',s)

name = input("Enter Molecule ID: ")

name_in = name+'.dat'

dtype = [('NO', int), ('LB', 'S2'), ('ZA', float), ('FRAG', int),
  ('MASS', float), ('X', float), ('Y', float), ('Z', float)]
data = np.genfromtxt(name_in, dtype=dtype, skip_header=3)

N =  data.shape[0]
a = np.array([data['X'], data['Y'], data['Z']])
anrows, ancols = np.shape(a)
a_new = a.reshape(anrows, 1, ancols)

diff = a_new - a

D = (diff ** 2).sum(2)
D = np.sqrt(D)
r = D

def eq7(a, s, Z):
 """
 Computes equation 7 in Molnar & King (2001)
 """
 N = r.shape[0]
 I = np.zeros(s.shape)
 for i in range(1, N):
 for j in range(i):
 I += Z[i] * Z[j] * np.sin(s * r[i, j])/(s * r[i, j])

 return I

I = eq7(r, s, data['ZA'])

name_s = name+'-Iz'
np.savetxt(name_s,I)

I_sq = []
I_sq = I**2
Area = []

name_s = name+'-Iz'

Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
I_z = np.sqrt(Area)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('Atomic Number Transform (FT$_z$)')
plt.show()
print('FTz: ',I_z)
name_s = name+'-FTz'
print(name_s)
np.savetxt(name_s,I_z)


#--
# MASS Mollecular Transform  FT_m


I = eq7(r, s, data['MASS'])

name_s = name+'-Im'

np.savetxt(name_s,I)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('MASS Transform (FT$_m$)')
plt.show()

I_sq = I**2
Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
np.savetxt('I_m',I,delimiter=' ')
I_m = np.sqrt([Area])

print('FTm: ',I_m)
name_s = name+'-FTm'
np.savetxt(name_s,I_m)

"""
#--


name_in = name+'.mpa.dat'

dtype_1 = [('NO', int), ('ATOM', 'S2'), ('NA', float), ('ZA', float),
  ('QA', float), ('VA', float), ('BVA', float), ('FA', float)]

data_1 = np.genfromtxt(name_in, dtype=dtype_1, skip_header=11)

qa = []
qa = np.array(data_1['QA'])
va = []
va = np.array([data_1['VA']])
bva =[]
bva = np.array([data_1['BVA']])
fa = []
fa = np.array([data_1['FA']])

#--

#Charge Molecular Transform  FT_c

I = eq7(r, s, data_1['QA'])
I_c = I

name_s = name+'-Ic'

np.savetxt(name_s,I)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(s.T, I)
fig.gca().set_xlabel("Distance (Å)")
plt.ylabel('Charge Transform (FT$_C$)')
plt.show()

I_sq = I_c**2
Area = np.trapz(I_sq,x=None,dx=0.01,axis=-1)
np.savetxt(name_s,I,delimiter=' ')
I_c = np.sqrt([Area])

print('FTc: ',I_c)
name_s = name+'-FTc'

np.savetxt(name_s,I_c)


"""

And here is the input file:

CARTESIAN COORDINATES (A.U.)

   NO LB  ZAFRAG MASS X       Y   Z
0 C 6.012.0110.000.000.00
1 H 1.0 1.0082.0598010.000.00
2 Br   35.079.900   -1.2031263.4029530.00
3 Cl   17.035.453   -1.108639   -1.5678532.715601
4 F 9.018.998   -0.938564   -1.327330   -2.299003

The last line in the script is causing the problem.

A pointer towards the solution to the problem will be much apprecialted.

Thanks in advance.



Problem solved: np.savetxt(name_s,I_z) should be np.savetxt(name_s,[I_z])

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Subtract a 1D Array from a 2D Array

2017-05-13 Thread Stephen P. Molnar

I am using Python 3.6 in Anaconda3 Spyder IDE.

I have two arrays:

X   Y  Z
a   
0   0  0
 2.059801   0  0
-1.2031263.402953  0
-1.108639   -1.5678532.715601
-0.938564   -1.32733-2.299003
   a_c  
0.42833750.91755 0.208299

and want to subtract the value of the value of each column or the array 
a_c from the each value in the corresponding column of array c.


Trying a_mm = a - a_c where a_mm is the new array results in the error 
message:


ValueError: operands could not be broadcast together with shapes (3,5) (1,3)

My search for a solution has not been successful.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subtract a 1D Array from a 2D Array

2017-05-13 Thread Stephen P. Molnar

On 05/13/2017 11:16 AM, eryk sun wrote:

On Sat, May 13, 2017 at 1:33 PM, Stephen P. Molnar
 wrote:

I am using Python 3.6 in Anaconda3 Spyder IDE.

I have two arrays:

 X   Y  Z
 a
 0   0  0
  2.059801   0  0
 -1.2031263.402953  0
 -1.108639   -1.5678532.715601
 -0.938564   -1.32733-2.299003
a_c
 0.42833750.91755 0.208299

and want to subtract the value of the value of each column or the array a_c
from the each value in the corresponding column of array c.

Trying a_mm = a - a_c where a_mm is the new array results in the error
message:

ValueError: operands could not be broadcast together with shapes (3,5) (1,3)

My search for a solution has not been successful.


You've presented array `a` as if it's 5x3, but the error says it's
3x5. If it were actually 5x3, there would be no problem:

 import numpy as np

 a = np.array([[0, 0, 0],
   [2.059801, 0, 0],
   [-1.203126, 3.402953, 0],
   [-1.108639, -1.567853, 2.715601],
   [-0.938564, -1.32733, -2.299003]])

 a_c = np.array([[0.4283375, 0.91755, 0.208299]])

 >>> a.shape
 (5, 3)
 >>> a_c.shape
 (1, 3)
 >>> a - a_c
 array([[-0.4283375, -0.91755  , -0.208299 ],
[ 1.6314635, -0.91755  , -0.208299 ],
[-1.6314635,  2.485403 , -0.208299 ],
[-1.5369765, -2.485403 ,  2.507302 ],
[-1.3669015, -2.24488  , -2.507302 ]])

You can use the transpose of either array. For example, use `a.T` to
get the same number of columns, or use `a_c.T` to get the same number
of rows.



That solved the problem.

Many thanks.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Pyuthon 3 Combine 1 D Arrays

2017-05-17 Thread Stephen P. Molnar
I'm beginning to think that I don't know how to ask the question as 
Google and Stack Overflow have resulted in nothing.  All of the results 
seem to deal with integers.


I have a number of single column floating point arrays each containing 
300 entries that I want to combine into a n by 300 array where n is the 
number of single column arrays.


I have tried zip, np.concatenate etc with only failure.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
1.00e+00
1.100334448160535050e+00
1.200668896321070322e+00
1.301003344481605373e+00
1.401337792642140423e+00
1.501672240802675695e+00
1.602006688963210745e+00
1.702341137123745796e+00
1.802675585284280846e+00
1.903010033444816118e+00
2.003344481605351390e+00
2.103678929765885997e+00
2.204013377926421491e+00
2.304347826086956541e+00
2.404682274247491591e+00
2.505016722408027086e+00
2.605351170568561692e+00
2.705685618729097186e+00
2.806020066889632236e+00
2.906354515050167286e+00
3.006688963210702337e+00
3.107023411371237387e+00
3.207357859531772437e+00
3.307692307692307931e+00
3.408026755852842982e+00
3.508361204013378032e+00
3.608695652173913082e+00
3.709030100334448132e+00
3.809364548494983183e+00
3.909698996655518677e+00
4.010033444816054171e+00
4.110367892976588777e+00
4.210702341137123383e+00
4.311036789297658878e+00
4.411371237458194372e+00
4.511705685618728978e+00
4.612040133779264472e+00
4.712374581939799967e+00
4.812709030100334573e+00
4.913043478260869179e+00
5.013377926421404673e+00
5.113712374581940168e+00
5.214046822742474774e+00
5.314381270903010268e+00
5.414715719063544874e+00
5.515050167224080369e+00
5.615384615384615863e+00
5.715719063545150469e+00
5.816053511705685963e+00
5.916387959866220569e+00
6.016722408026756064e+00
6.117056856187290670e+00
6.217391304347826164e+00
6.317725752508361658e+00
6.418060200668896265e+00
6.518394648829431759e+00
6.618729096989966365e+00
6.719063545150501859e+00
6.819397993311037354e+00
6.919732441471571960e+00
7.020066889632107454e+00
7.120401337792642060e+00
7.220735785953177555e+00
7.321070234113712161e+00
7.421404682274247655e+00
7.521739130434783149e+00
7.622073578595317755e+00
7.722408026755853250e+00
7.822742474916387856e+00
7.923076923076923350e+00
8.023411371237457956e+00
8.123745819397992562e+00
8.224080267558528945e+00
8.324414715719063551e+00
8.424749163879599934e+00
8.525083612040134540e+00
8.625418060200669146e+00
8.725752508361203752e+00
8.826086956521738358e+00
8.926421404682274741e+00
9.026755852842809347e+00
9.127090301003343953e+00
9.227424749163880335e+00
9.327759197324414941e+00
9.428093645484949548e+00
9.528428093645485930e+00
9.628762541806020536e+00
9.729096989966555142e+00
9.829431438127089748e+00
9.929765886287626131e+00
1.003010033444816074e+01
1.013043478260869534e+01
1.023076923076923173e+01
1.033110367892976633e+01
1.043143812709030094e+01
1.053177257525083554e+01
1.063210702341137193e+01
1.073244147157190653e+01
1.083277591973244114e+01
1.093311036789297752e+01
1.103344481605351213e+01
1.113377926421404673e+01
1.123411371237458134e+01
1.133444816053511772e+01
1.143478260869565233e+01
1.153511705685618693e+01
1.163545150501672332e+01
1.173578595317725792e+01
1.183612040133779253e+01
1.193645484949832891e+01
1.203678929765886352e+01
1.213712374581939812e+01
1.223745819397993273e+01
1.233779264214046911e+01
1.243812709030100372e+01
1.253846153846153832e+01
1.263879598662207471e+01
1.273913043478260931e+01
1.283946488294314392e+01
1.293979933110367853e+01
1.304013377926421491e+01
1.314046822742474951e+01
1.324080267558528412e+01
1.334113712374582050e+01
1.344147157190635511e+01
1.354180602006688972e+01
1.364214046822742432e+01
1.374247491638796070e+01
1.384280936454849531e+01
1.394314381270902992e+01
1.404347826086956630e+01
1.414381270903010090e+01
1.424414715719063551e+01
1.434448160535117012e+01
1.81605351170650e+01
1.454515050167224111e+01
1.464548494983277571e+01
1.474581939799331209e+01
1.484615384615384670e+01
1.494648829431438131e+01
1.504682274247491591e+01
1.514715719063545230e+01
1.524749163879598690e+01
1.534782608695652151e+01
1.544816053511705789e+01
1.554849498327759250e+01
1.564882943143812710e+01
1.574916387959866171e+01
1.584949832775919809e+01
1.594983277591973270e+01
1.605016722408026908e+01
1.615050167224080369e+01
1.625083612040133829e+01
1.635117056856187290e+01
1.645150501672240750e+01
1.655183946488294566e+01
1.665217391304347672e+01
1.675250836120401488e+01
1.685284280936454948e+01
1.695317725752508409e+01
1.705351170568561869e+01
1.715384615384615330e+01
1.725418060200668791e+01
1.735451505016722606e+01
1.745484949832776067e+01
1.755518394648829528e+01
1.765551839464882988e+01
1.775585284280936449e+01
1.785618729096989910e+01
1.795652173913043370e+01
1.805685618729097186e+01
1.815719063545150647e+01
1.825752508361204107e+01
1.835785953177257568e+01
1.845819397993311028e+01
1.855852842809

Re: [Tutor] Pyuthon 3 Combine 1 D Arrays

2017-05-18 Thread Stephen P. Molnar

On 05/17/2017 06:15 PM, Luis JM Amoreira wrote:

Hi,
If your arrays have shape (300,1) (single column, 300 rows right?) then
M = numpy.hstack((array1, array2)) is an array with shape (300, 2) (300
rows, 2 columns) and M.T is 2 by 300 [shape (2, 300)]. Take an example:

In [11]: import numpy as np

In [12]: a1=np.random.rand(3,1)

In [13]: a1
Out[13]:
array([[ 0.09042866],
[ 0.63008665],
[ 0.99106757]])

In [14]: a2=np.random.rand(3,1)

In [15]: np.hstack((a1,a2))
Out[15]:
array([[ 0.09042866,  0.99965848],
[ 0.63008665,  0.12334957],
[ 0.99106757,  0.43502637]])

In [16]: np.hstack((a1,a2)).T
Out[16]:
array([[ 0.09042866,  0.63008665,  0.99106757],
[ 0.99965848,  0.12334957,  0.43502637]])

Hope this helps!
ze


On 05/17/2017 08:50 PM, Stephen P. Molnar wrote:

I'm beginning to think that I don't know how to ask the question as
Google and Stack Overflow have resulted in nothing.  All of the
results seem to deal with integers.

I have a number of single column floating point arrays each containing
300 entries that I want to combine into a n by 300 array where n is
the number of single column arrays.

I have tried zip, np.concatenate etc with only failure.

Thanks in advance.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




Thanks for your reply.

Here's what I get:

Traceback (most recent call last):

  File "", line 1, in 

runfile('/home/comp/Apps/Python/Molecular_Transforms/Basic/MolT_app_1.py', 
wdir='/home/comp/Apps/Python/Molecular_Transforms/Basic')


  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 880, in runfile

execfile(filename, namespace)

  File 
"/home/comp/Apps/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", 
line 102, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)

  File 
"/home/comp/Apps/Python/Molecular_Transforms/Basic/MolT_app_1.py", line 
289, in 

f.write("\n".join("".join(map(str, x)) for x in (name_I_app)))

  File 
"/home/comp/Apps/Python/Molecular_Transforms/Basic/MolT_app_1.py", line 
289, in 

f.write("\n".join("".join(map(str, x)) for x in (name_I_app)))

TypeError: 'numpy.float64' object is not iterable

However, numpy.column_stack works.

Problem solved.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-05 Thread Stephen P. Molnar

On 06/04/2017 04:44 AM, Abdur-Rahmaan Janhangeer wrote:

Wing. Wing IDE personal works awesome for me

Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com

On 3 Jun 2017 02:59, "C W"  wrote:


Dear Python list,

I am an R user learning Python. What is a good editor?

1) Pycharm
PyCharm evaluates the entire script, I just want to change a few lines in
the script.
For example,

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1,0.1)
y = np.sin(2 * np.pi * x)

plt.figure(1)
plt.clf()
plt.plot(x, y)
plt.show()

Now, I want to do a scatter plot, but don't want to generate the data
again. I just want the "line by line" evaluation like in R and Matlab.
Basically, you can type in console and add to the existing variables.

2) Spyder
Spyder looks a lot like RStudio, I like it! But, it does not have an app
icon in applications.  I am baffled. I do ~/anaconda/bin/spyder every time.

Am I missing something or is this the way it is?

Thank you very much!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Here's how I start Spyder, in Xfce:

/home/comp/Apps/anaconda3/bin/spyder

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with Plot Legend

2017-06-13 Thread Stephen P. Molnar
I am using Python3.6 in the Spyder3IDE and have a problem with the 
legend for a plot.


I have attached the pg file.

The code (in part) is:
import numpy as np
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

.
.
.
(the portion of the code for Figure q1 has no problems)


def two_scales(ax1, time, data1, data2, c1, c2)

ax2 = ax1.twinx()

ax1.plot(time, data1, 'r')
ax1.set_xlabel("Distance ($\AA$)")
ax1.set_ylabel('Atom Charge',color='r')

ax2.plot(time, data2, 'b')
ax2.set_ylabel('Orbital Energy',color='b')
return ax1, ax2



t = data[:,0]
s1 = data[:,3]
s2 = data[:,5]

# Create axes
fig, ax = plt.subplots()
ax1, ax2 = two_scales(ax, t, s1, s2, 'r', 'b')


# Change color of each axis
def color_y_axis(ax, color):
"""Color your axes."""
for t in ax.get_yticklabels():
t.set_color(color)
return None
color_y_axis(ax1, 'r')
color_y_axis(ax2, 'b')

plt.title('Molecular Transforms')

patch_red = mpatches.Patch(color='red',label='Atom Charge')
patch_blue = mpatches.Patch(color='blue',label='Orbital Energy')
plt.legend(handles = [patch_red,patch_blue])

plt.draw()
plt.show()

name_plt = name+'-fig2.png'
fig.savefig(name_plt,bbox_inches='tight')

The problem is that the legend is where I want it in the figure and 
contains what I want with one exception:


The colored lines are too thick, the same width as the text.

I've look in the literature and Googled for the solution, but I'm 
beginning to think that I don't know just what the question that I 
should be asking, hence no results.


A pointer towards thech solution to this problem will be much appreciated.

Thanks in advance.
--
Stephen P. Molnar, Ph.D.
Consultant
www.molecular-modeling.net
(614)312-7528 (c)
Skype: smolnar1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] AttributeError: 'BezierPath' object has no attribute '_draw_solid'

2017-11-19 Thread Stephen P. Molnar
I have written a short Python 3 script to plot three curves (one plot) 
of data from a FORTRAN program.  Initially the code worked and produced 
the plot which is attached.  I have also attached the code and the input 
data,


In all candor, I don't have the faintest idea as to whst the problem (or 
problens) might be and would greatly appreciate a pointer towards the 
solution.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1

   0.15  1457.204006   998.233839-0.018612
   0.30  1344.817934   931.699910-0.017571
   0.45  1170.330414   827.700509-0.015915
   0.60   951.240195   695.702122-0.013757
   0.75   708.832611   547.341272-0.011238
   0.90   465.526861   395.074189-0.008520
   1.05   242.168335   250.776922-0.005770
   1.2055.640011   124.478386-0.003147
   1.35   -82.88923823.385404-0.000790
   1.50  -168.863907   -48.686568 0.001192
   1.65  -204.304928   -91.423531 0.002725
   1.80  -196.892849  -107.676083 0.003774
   1.95  -158.353900  -102.749215 0.004342
   2.10  -102.425393   -83.440486 0.004465
   2.25   -42.724395   -56.976574 0.004210
   2.40 9.160768   -30.003148 0.003659
   2.5545.090063-7.765044 0.002907
   2.7061.128133 6.423416 0.002048
   2.8557.57734711.367836 0.001171
   3.0038.344275 7.846857 0.000349
   3.15 9.797326-1.817135-0.000359
   3.30   -20.657232   -14.377418-0.000917
   3.45   -46.025084   -26.358616-0.001307
   3.60   -60.958617   -34.712347-0.001528
   3.75   -62.589086   -37.332393-0.001596
   3.90   -50.849425   -33.359410-0.001536
   4.05   -28.274206   -23.244463-0.001380
   4.20 0.647490-8.581977-0.001162
   4.3530.419924 8.240844-0.000915
   4.5055.60181224.504898-0.000668
   4.6571.78689037.644793-0.000444
   4.8076.33744645.676179-0.000259
   4.9568.75857947.497775-0.000122
   5.1050.67117043.026846-0.36
   5.2525.41446833.157608 0.01
   5.40-2.62785219.562143-0.04
   5.55   -28.841964 4.378077-0.39
   5.70   -49.186470   -10.157324-0.95
   5.85   -60.843330   -22.062653-0.000159
   6.00   -62.613119   -29.900128-0.000219
   6.15   -55.002707   -32.954002-0.000264
   6.30   -40.011347   -31.279440-0.000284
   6.45   -20.674231   -25.624738-0.000272
   6.60-0.461617   -17.250484-0.000223
   6.7517.349547-7.684285-0.000134
   6.9030.217978 1.543060-0.07
   7.0536.704572 9.135157 0.000153
   7.2036.61156414.205163 0.000340
   7.3530.88790416.366163 0.000542
   7.5021.33750015.730856 0.000745
   7.6510.20032712.830456 0.000931
   7.80-0.305538 8.475307 0.001083
   7.95-8.392428 3.587153 0.001184
   8.10   -12.989800-0.965458 0.001218
   8.25   -13.865349-4.501286 0.001173
   8.40   -11.571637-6.611087 0.001043
   8.55-7.243459-7.184785 0.000828
   8.70-2.298165-6.384063 0.000537
   8.85 1.893836-4.572551 0.000186
   9.00 4.300063-2.221752-0.000202
   9.15 4.422590 0.187190-0.000598
   9.30 2.366936 2.247742-0.000969
   9.45-1.222319 3.685155-0.001284
   9.60-5.337564 4.380342-0.001511
   9.75-8.852834 4.361341-0.001629
   9.90   -10.782542 3.769297-0.0

Re: [Tutor] AttributeError: 'BezierPath' object has no attribute '_draw_solid'

2017-11-19 Thread Stephen P. Molnar


On 11/19/2017 03:10 PM, William Ray Wing wrote:

On Nov 19, 2017, at 11:36 AM, Stephen P. Molnar  wrote:

I have written a short Python 3 script to plot three curves (one plot) of data 
from a FORTRAN program.  Initially the code worked and produced the plot which 
is attached.  I have also attached the code and the input data,


The data made it through, neither the script nor the plot did.  If the script 
really is short, perhaps you could just cut and paste it into a follow-up msg.  
Absent that, no one here can help you.

Thanks,
Bill


In all candor, I don't have the faintest idea as to whst the problem (or 
problens) might be and would greatly appreciate a pointer towards the solution.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




Here it is:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Multiple_Plots_2_b.py

Copyright (c) 2017 Stephen P. Molnar, Ph.D.  All rights reserved.

"""
import numpy as np
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt

data = []
name = input("Enter Molecule ID: ")

name_in = name+'_poutput'
data = np.genfromtxt(name_in)

s = data[:,0]
FTm = data[:,1] #atomic number
FTe = data[:,2] #atomic mass
FTc = data[:,3] #atom electron density


fig = plt.figure(figsize=(7.6,4))

host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twinx()
par2 = host.twinx()

offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2,
offset=(offset, 0))

par2.axis["right"].toggle(all=True)

host.set_xlim(0, 30)
"""
host.set_ylim(min(FTm), max(FTm))
"""

host.set_xlabel("Distance ($\AA$)")
host.set_ylabel("Atomic Number")
par1.set_ylabel("Atom Mass")
par2.set_ylabel("Atom Electron Density")

p1, = host.plot(data[:,0], data[:,1])#, label="Atomic Number")
p2, = par1.plot(data[:,0], data[:,2])#, label="Atom Mass")
p3, = par2.plot(data[:,0], data[:,3])#, label="Atom Electron Density")

"""
par1.set_ylim(min(FTe), max(FTe))
par2.set_ylim(min(FTc),max(FTc))
"""

#host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right"].label.set_color(p3.get_color())

host.title.set_text('Molecule {0} - Molecular Transforms'.format(name))
plt.draw()
plt.show()

name_plt = name+'-fig1.png'
fig.savefig(name_plt,bbox_inches='tight')


--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] AttributeError: 'BezierPath' object has no attribute '_draw_solid'

2017-11-20 Thread Stephen P. Molnar


On 11/20/2017 06:24 AM, Steven D'Aprano wrote:

On Mon, Nov 20, 2017 at 10:26:50AM +, Alan Gauld via Tutor wrote:


Actually, pasting code etc is safer since the server removes
attachments. And while it is supposed to preserve plain text
attachments it will throw them away if it sees *anything*
that it thinks looks like binary.

Let's do a test and see what happens! Attached is a .py file in UTF-8.
If that passes through, I think we're good :-)



Also some readers are on
corporate accounts that strip all attachments regardless
of type

Given the popularity of HTML email, corporate logos attached as images,
and the ubiquity of emailing PDF and DOC/DOCX files in the business
world, I would be stunned to come across any corporation that stripped
all attachements.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Many thanks.  Indeed it worked!

I'm not really looking for someone to do the programming for me.  I know 
that the code works, because it did and produced the attached plot. I 
just don't know why it stopped working.  Actually, all of my programming 
experience has been with FORTRAN, starting with II in 1961 (yes, I am 
rather an old... an Organic Chemist.


Let's start over,

This is the code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Multiple_Plots_2_b.py

Copyright (c) 2017 Stephen P. Molnar, Ph.D.  All rights reserved.

"""
import numpy as np
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt

data = []
name = input("Enter Molecule ID: ")

name_in = name+'_poutput'
data = np.genfromtxt(name_in)

s = data[:,0]
FTm = data[:,1] #atomic number
FTe = data[:,2] #atomic mass
FTc = data[:,3] #atom electron density


fig = plt.figure(figsize=(7.6,4))

host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twinx()
par2 = host.twinx()

offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2,
offset=(offset, 0))

par2.axis["right"].toggle(all=True)

host.set_xlim(0, 30)
"""
host.set_ylim(min(FTm), max(FTm))
"""

host.set_xlabel("Distance ($\AA$)")
host.set_ylabel("Atomic Number")
par1.set_ylabel("Atom Mass")
par2.set_ylabel("Atom Electron Density")

p1, = host.plot(data[:,0], data[:,1])#, label="Atomic Number")
p2, = par1.plot(data[:,0], data[:,2])#, label="Atom Mass")
p3, = par2.plot(data[:,0], data[:,3])#, label="Atom Electron Density")

"""
par1.set_ylim(min(FTe), max(FTe))
par2.set_ylim(min(FTc),max(FTc))
"""

#host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right"].label.set_color(p3.get_color())

host.title.set_text('Molecule {0} - Molecular Transforms'.format(name))
plt.draw()
plt.show()

name_plt = name+'-fig1.png'
fig.savefig(name_plt,bbox_inches='tight')


And the input file A_poutput:

   0.15  1457.204006   998.233839-0.018612
   0.30  1344.817934   931.699910-0.017571
   0.45  1170.330414   827.700509-0.015915
   0.60   951.240195   695.702122-0.013757
   0.75   708.832611   547.341272-0.011238
   0.90   465.526861   395.074189-0.008520
   1.05   242.168335   250.776922-0.005770
   1.2055.640011   124.478386-0.003147
   1.35   -82.88923823.385404-0.000790
   1.50  -168.863907   -48.686568 0.001192
   1.65  -204.304928   -91.423531 0.002725
   1.80  -196.892849  -107.676083 0.003774
   1.95  -158.353900  -102.749215 0.004342
   2.10  -102.425393   -83.440486 0.004465
   2.25   -42.724395   -56.976574 0.004210
   2.40 9.160768   -30.003148 0.003659
   2.5545.090063-7.765044 0.002907
   2.7061.128133 6.423416 0.002048
   2.8557.57734711.367836 0.001171
   3.0038.344275 7.846857 0.000349
   3.15 9.797326-1.817135-0.000359
   3.30   -20.657232   -14.377418-0.000917
   3.45   -46.025084   -26.358616-0.001307
   3.60   -60.958617   -34.712347 

Re: [Tutor] AttributeError: 'BezierPath' object has no attribute '_draw_solid'

2017-11-20 Thread Stephen P. Molnar


On 11/20/2017 09:34 AM, William Ray Wing wrote:


On Nov 19, 2017, at 3:14 PM, Stephen P. Molnar 
mailto:s.mol...@sbcglobal.net>> wrote:



On 11/19/2017 03:10 PM, William Ray Wing wrote:
On Nov 19, 2017, at 11:36 AM, Stephen P. Molnar 
mailto:s.mol...@sbcglobal.net>> wrote:


I have written a short Python 3 script to plot three curves (one 
plot) of data from a FORTRAN program.  Initially the code worked 
and produced the plot which is attached.  I have also attached the 
code and the input data,


The data made it through, neither the script nor the plot did.  If 
the script really is short, perhaps you could just cut and paste 
it into a follow-up msg.  Absent that, no one here can help you.


Thanks,
Bill



As an experiment, I took the code and moved it to my laptop (MacOS, 
running 10.12.6 where there is a complete Anaconda installation that 
contains self-consistent versions of everything Dr. Molnar imports 
(Python 3.6.1 incidentally).  There the code runs perfectly.  I’m 
appending a copy of the .png file it produced, and although I expect 
it to be scraped off by the gateway list-server, it should show up in 
Dr. Molnar’s e-mail.


Bill



In all candor, I don't have the faintest idea as to whst the 
problem (or problens) might be and would greatly appreciate a 
pointer towards the solution.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net 
<http://www.molecular-modeling.net>Stochastic and multivariate

(614)312-7528 (c)
Skype: smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




Here it is:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Multiple_Plots_2_b.py

Copyright (c) 2017 Stephen P. Molnar, Ph.D.  All rights reserved.

"""
import numpy as np
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt

data = []
name = input("Enter Molecule ID: ")

name_in = name+'_poutput'
data = np.genfromtxt(name_in)

s = data[:,0]
FTm = data[:,1] #atomic number
FTe = data[:,2] #atomic mass
FTc = data[:,3] #atom electron density


fig = plt.figure(figsize=(7.6,4))

host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twinx()
par2 = host.twinx()

offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2,
   offset=(offset, 0))

par2.axis["right"].toggle(all=True)

host.set_xlim(0, 30)
"""
host.set_ylim(min(FTm), max(FTm))
"""

host.set_xlabel("Distance ($\AA$)")
host.set_ylabel("Atomic Number")
par1.set_ylabel("Atom Mass")
par2.set_ylabel("Atom Electron Density")

p1, = host.plot(data[:,0], data[:,1])#, label="Atomic Number")
p2, = par1.plot(data[:,0], data[:,2])#, label="Atom Mass")
p3, = par2.plot(data[:,0], data[:,3])#, label="Atom Electron Density")

"""
par1.set_ylim(min(FTe), max(FTe))
par2.set_ylim(min(FTc),max(FTc))
"""

#host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right"].label.set_color(p3.get_color())

host.title.set_text('Molecule {0} - Molecular Transforms'.format(name))
plt.draw()
plt.show()

name_plt = name+'-fig1.png'
fig.savefig(name_plt,bbox_inches='tight')


--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net 
<http://www.molecular-modeling.net>Stochastic and multivariate

(614)312-7528 (c)
Skype: smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Hmm!  I'm relieved that the code works!

I've just encountered something strange.

I haven't been using Python very long, only about six months or so. When 
I started I  look at a number of different IDE, and settled on Spyder, 
although not in Anaconda.  I just installed Canopy in order to use the 
ipython notebook, and the code ran perfectly in the Canopy editor  
Perhaps I should switch IDE's, but I rather like the Variable Explorer 
feature in Spyder.


--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
www.molecular-modeling.net  Stochastic and multivariate
(614)312-7528 (c)
Skype: smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] AttributeError: 'BezierPath' object has no attribute '_draw_solid'

2017-11-20 Thread Stephen P. Molnar


On 11/20/2017 10:18 AM, Steven D'Aprano wrote:

On Mon, Nov 20, 2017 at 08:18:41AM -0500, Stephen P. Molnar wrote:


I'm not really looking for someone to do the programming for me.  I know
that the code works, because it did and produced the attached plot. I
just don't know why it stopped working.  Actually, all of my programming
experience has been with FORTRAN, starting with II in 1961 (yes, I am
rather an old... an Organic Chemist.

Let's start over,

This is the code:

You seem to have completely ignored my advice about cutting the code
down to the minimum amount that demonstrates the error. Okay, that's
your perogative, but as a volunteer it is my perogative to choose how
much or how little effort I put into solving your problem for you.

I have neither the time nor the inclination to spend a lot of time on
this, so I'll just offer one suggestion. According to the error
traceback, you appear to be running the script from inside either the
Spyder IDE, or possibly an iPython/Jupyter notebook.

This appears to be the command you are running (inside iPython?):


runfile('/home/comp/Apps/Python/Plot_T_Data/MultiplePlots_3.py', 
wdir='/home/comp/Apps/Python/Plot_T_Data')

and the traceback shows a failure relating to iPython and/or Spyder:


   File "", line 1, in 
 runfile('/home/comp/Apps/Python/Plot_T_Data/MultiplePlots_3.py', 
wdir='/home/comp/Apps/Python/Plot_T_Data')

   File 
"/usr/local/lib/python3.5/dist-packages/spyder/utils/site/sitecustomize.py", 
line 688, in runfile
 execfile(filename, namespace)


It is possible that you have recently updated iPython or installed
Spyder, and that has broken your script. I recommend that you eliminate
them from contention, by running your script from the old-fashioned
Linux commandline. From bash, or some other terminal shell, run:


cd /home/comp/Apps/Python/Plot_T_Data
python3.5 MultiplePlots_3.py


and see if the error persists. If the error goes away, then the problem
lies in iPython or Spyder.

In a nutshell, based on a cursory look at the traceback, this seems to
be a problem with your environment rather than your code.

Good luck!



Followed your advice;

comp@AbNormal:~/Apps/Models/Fluoranthene/ReferenceMolecules/Output/Transforms_1$ 
python3.5 MultiplePlots_3.py

Enter Molecule ID: Chrysene
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1562, in __call__
return self.func(*args)
  File "/usr/lib/python3.5/tkinter/__init__.py", line 608, in callit
func(*args)
  File 
"/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_tkagg.py", 
line 323, in idle_draw

self.draw()
  File 
"/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_tkagg.py", 
line 304, in draw

FigureCanvasAgg.draw(self)
  File 
"/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_agg.py", 
line 430, in draw

self.figure.draw(self.renderer)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py", 
line 55, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py", 
line 1295, in draw

renderer, self, artists, self.suppressComposite)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/image.py", 
line 138, in _draw_list_compositing_images

a.draw(renderer)
  File 
"/usr/lib/python3/dist-packages/mpl_toolkits/axes_grid1/parasite_axes.py", 
line 295, in draw

self._get_base_axes_attr("draw")(self, renderer)
  File 
"/usr/lib/python3/dist-packages/mpl_toolkits/axisartist/axislines.py", 
line 778, in draw

super(Axes, self).draw(renderer, inframe)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py", 
line 55, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)
  File 
"/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_base.py", line 
2399, in draw

mimage._draw_list_compositing_images(renderer, self, artists)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/image.py", 
line 138, in _draw_list_compositing_images

a.draw(renderer)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/artist.py", 
line 55, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)
  File 
"/usr/lib/python3/dist-packages/mpl_toolkits/axisartist/axis_artist.py", 
line 1572, in draw

self._draw_line(renderer)
  File 
"/usr/lib/python3/dist-packages/mpl_toolkits/axisartist/axis_artist.py", 
line 1170, in _draw_line

self.line.draw(renderer)
  File 
"/usr/lib/python3/dist-packages/mpl_toolkits/axisartist/axis_artist.py", 
line 163, in draw

lineFunc = getattr(self, funcname)
AttributeError: 'BezierPath' 

[Tutor] Problem with Saved File

2019-04-05 Thread Stephen P. Molnar
I am using Spyder v-3.3.3 on Debian Stretch and have written a script to 
process data from another application.  I am having a problem saving the 
resulting file [A] as a column vector.


The vector is saved by  np.savetxt(name_s,[A]).

When I open the file in Spyder it is a column vector, but when I import 
the saved file into QtiPlot it is a line vector.


What am I missing in the savetxt statement?

Thanks in advance

--
Stephen P. Molnar, Ph.D.  Life is a fuzzy set
www.molecular-modeling.netStochastic and multivariate
(614)312-7528(c)
Skype:  smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with Saved File

2019-04-07 Thread Stephen P. Molnar
I am using Spyder v-3.3.3 on Debian Stretch and have written a script to 
process data from another application.  I am having a problem saving the 
resulting file [A] as a column vector.


The vector is saved by  np.savetxt(name_s,[A]).

When I open the file in Spyder it is a column vector, but when I import 
the saved file into QtiPlot it is a line vector.


What am I missing in the savetxt statement?

Thanks in advance

--
Stephen P. Molnar, Ph.D.  Life is a fuzzy set
www.molecular-modeling.netStochastic and multivariate
(614)312-7528(c)
Skype:  smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Two Scripts, Same Commands, One Works, One Doesn't

2019-05-15 Thread Stephen P. Molnar
I am writing scripts to semi-automate some of my Quantum Chemistry 
software and have encountered a problem that has me baffled. The two 
scripts have the same form, the only difference being the commands. One 
script works, the other bombs.


The script that works is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
calc_pdbqt

Created on Mon May 13 09:50:54 2019

copyrignt (c) 2019 Stephen P. Molnar, Ph.D.  All rights reserved
"""

import subprocess
with open('ligand') as infile:
ligand = infile.read().strip().split()
for nvar in ligand:
command = ["./pythonsh", "./prepare_ligand4.py",
"-l", nvar + ".mol2",
"-o", nvar + ".pdbqt" ]
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
out, err = proc.communicate()
print(out)
print(err)
if proc.returncode:
print ('Subprocess FAILED:', proc.command)


while the script that bombs is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
calc_pdf4

Created on Mon May 13 09:50:54 2019

copyrignt (c) 2019 Stephen P. Molnar, Ph.D.  All rights reserved
"""

import subprocess
with open('ligand') as infile:
ligand = infile.read().strip().split()
for nvar in ligand:
command = ["./pythonsh", "./prepare_pdf4.py",
"-l", nvar + ".pdbqt",
"-ro", nvar + ".dpf" ]
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
out, err = proc.communicate()
print(out)
print(err)
if proc.returncode:
print ('Subprocess FAILED:', proc.command)

The errors are:

runfile('/home/comp/Apps/Models/1-NerveAgents/Ligands/calc_pdf.py', 
wdir='/home/comp/Apps/Models/1-NerveAgents/Ligands')

b''
None
/sdc1/Apps/MGLTools2-1.1/bin/python: can't open file 
'./prepare_pdf4.py': [Errno 2] No such file or directory

Traceback (most recent call last):

  File "", line 1, in 
runfile('/home/comp/Apps/Models/1-NerveAgents/Ligands/calc_pdf.py', 
wdir='/home/comp/Apps/Models/1-NerveAgents/Ligands')


  File 
"/home/comp/Apps/miniconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", 
line 824, in runfile

execfile(filename, namespace)

  File 
"/home/comp/Apps/miniconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", 
line 110, in execfile

exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/comp/Apps/Models/1-NerveAgents/Ligands/calc_pdf.py", line 
23, in 

print ('Subprocess FAILED:', proc.command)

AttributeError: 'Popen' object has no attribute 'command'

I have attached the two scripts that are called and a test input file.

Googling has not helped me to find a solution and I would greatly 
appreciate your assistance.


Thanks in advance.

--
Stephen P. Molnar, Ph.D.  Life is a fuzzy set
www.molecular-modeling.netStochastic and multivariate
(614)312-7528(c)
Skype:  smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Two Scripts, Same Commands, One Works, One Doesn't

2019-05-16 Thread Stephen P. Molnar

Thanks for your reply. I am most appreciative of your detailed response.

Please see below for my comments.

On 05/15/2019 08:12 PM, Steven D'Aprano wrote:

Hi Stephen,

My responses are interleaved with your comments below. Please excuse the
length of my post, but your problem is a complicated one.


On Wed, May 15, 2019 at 08:16:02AM -0400, Stephen P. Molnar wrote:

I am writing scripts to semi-automate some of my Quantum Chemistry
software and have encountered a problem that has me baffled. The two
scripts have the same form, the only difference being the commands. One
script works, the other bombs.

A note on terminology: to programmers, the terminology "bombs" usually
refers to a fatal application crash detected by the operating system:

https://en.wikipedia.org/wiki/Bomb_%28icon%29

whereas what you are experiencing is merely an exception with a
traceback displayed. The difference is that a "bomb" (or a "crash") is a
serious bug in the application (Python), while an exception is actually
a sign that Python is working correctly.

The bottom line is that there's not much you can do about a bomb except
stop running the script, whereas an exception means there's a bug in
your code you can fix.



My use of computers in my scientific work goes back to the early 1960's 
as a graduate student when I took an introductory course in FORTRAN II. 
I am a Chemist and not a professional programmer, although I 
occasionally write a FORTRAN program, thanks to Linux and gfortran. 
Although retired, I am still maintaining a computational chemistry 
research program.


So, substitute 'bug' for 'bomb' in this thread.

The script that works is:

[...]

Thanks for the careful and detailed samples of your code, but in general
unless you are paying a consultant to to the work for you, it is best to
try to narrow down the samples to the smallest amount that demonstrates
the problem. We're volunteers, donating our time for free, and often
with very limited time to offer. Every extra line of code you present us
with discourages us a little more from tackling your problem, so the
smaller the amount of code, the more likely we are to help.

For a better explanation, you might like to read this:

http://www.sscce.org/

It is written for Java programmers but applies to any language.




#!/usr/bin/env python

This line tells a Unix system to run the script using "python", which is
probably going to be Python 2. But I see from your code below that you
are actually running Python 3 code. So this is a potential problem. I
cannot tell if it is *actually* a problem right now, or will only become
one in the future.

You could try replacing the word "python" with "python3", but you should
run these commands at the Unix shell first:

 env python
 env python3

and see what they say.

Another problem is that both of your scripts call out to an external
script `pythonsh` which we cannot see, so there's no way of knowing what
that is doing.


Pythonsh is a bash script, a part of MGL_Tools 
(http://mgltools.scripps.edu/) which is the source of prepare_ligand4.py 
and prepare_dpf4.py which I am attempting to implement in my two 
scripts.  MGL_Tools is a gui for AutoDock which, in turn I have been 
using for at least 25 years now. (Both MGL_Tools and AutoDock are open 
source and have been widely used.)


The function of pythonsh is to establish an environment for the use of 
python2 and to set a number of paths..  If I invoke pythonsh in a bash 
shell I get:


comp@AbNormal:/sdc1/Apps/Models/1-NerveAgents/Scripts$ ./pythonsh
setting PYTHONHOME environment
Python 2.5.6 (r256:88840, Nov  6 2012, 15:29:26)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


The second script refers to yet another Python script
`prepare_pdf4.py` but the output says this file doesn't exist:

can't open file
'./prepare_pdf4.py': [Errno 2] No such file or directory


So that's a problem you need to fix. I have no idea if that will fix
everything, or just part of the issue.




The problem may not be the invocation of prepare_dpf4.py, because:

comp@AbNormal:/sdc1/Apps/Models/1-NerveAgents/Ligands$ ./pythonsh 
./prepare_dpf4.py

prepare_dpf4.py: ligand and receptor filenames
must be specified.
Usage: prepare_dpf4.py -l pdbqt_file -r pdbqt_file
-l ligand_filename
-r receptor_filename

Optional parameters:
[-o output dpf_filename]
[-i template dpf_filename]
[-x flexres_filename]
[-p parameter_name=new_value]
[-k list of parameters to write]
[-e write epdb dpf ]
[-v] verbose output
[-L] use local search parameters
[-S] use simulated annealing search parameters
[-s] seed population using ligand's present conformation

Prep

[Tutor] Search for Text in File

2019-08-15 Thread Stephen P. Molnar
I need to find a phrase in i text file in order to read a unique text 
string into a python3 application.


I have become stuck and Google has not been of any use.

Here is my attempt:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  Extract.Data.py
#
#
#
#  "


import re

name = input("Enter Molecule Name: ")

name_in = name+'_apo-1acl.dlg'
re.search("RMSD TABLE",name_in())

and here is the portion of the text file (Acetyl_apo-1acl.dlg) 
containing the information:




 |   | |   | |
Clus | Lowest| Run | Mean  | Num | Histogram
-ter | Binding   | | Binding   | in  |
Rank | Energy| | Energy| Clus|510   15   20 25   30   35
_|___|_|___|_|:|:|:|:___
   1 | -4.39 |  15 | -4.29 |   2 |##
   2 | -4.38 |  13 | -4.27 |   6 |##
   3 | -4.29 |  11 | -4.15 |  10 |##
   4 | -3.90 |   9 | -3.90 |   2 |##
_|___|_|___|_|__


Number of multi-member conformational clusters found = 4, out of 20 runs.

RMSD TABLE
__

_
 |  |  |   | | |
Rank | Sub- | Run  | Binding   | Cluster | Reference   | Grep
 | Rank |  | Energy| RMSD| RMSD| Pattern
_|__|__|___|_|_|___
   1  1 15   -4.39  0.00 92.25   RANKING
   1  2 17   -4.19  0.99 92.15   RANKING
   2  1 13   -4.38  0.00 93.14   RANKING
   2  2  6   -4.37  1.21 92.80   RANKING
   2  3 18   -4.35  0.87 93.26   RANKING
   2  4  5   -4.33  1.23 92.85   RANKING
   2  5  3   -4.17  1.17 93.40   RANKING
   2  6  7   -3.99  1.33 92.98   RANKING
   3  1 11   -4.29  0.00 91.37   RANKING
   3  2 19   -4.29  0.31 91.27   RANKING
   3  3 16   -4.25  1.08 91.14   RANKING
   3  4 10   -4.25  0.86 91.13   RANKING
   3  5  1   -4.13  0.94 91.83   RANKING
   3  6 20   -4.11  1.03 91.89   RANKING
   3  7 12   -4.11  0.60 91.28   RANKING
   3  8  2   -4.10  0.86 91.56   RANKING
   3  9  8   -4.09  0.73 91.52   RANKING
   3 10  4   -3.89  1.24 91.91   RANKING
   4  1  9   -3.90  0.00 95.00   RANKING
   4  2 14   -3.90  0.92 94.92   RANKING
___



INFORMATION ENTROPY ANALYSIS FOR THIS CLUSTERING



Information entropy for this clustering = 0.39  (rmstol = 2.00 Angstrom)

Everything that I have tried returns 'TypeError: 'str' object is not 
callable'.


Assistance will be much appreciated.

Thanks in advance.

--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
http://www.Molecular-Modeling.net   Multivariate and stochastic
614.312.7528 (c)
Skype:  smolnar1

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor