X-Received: by 10.107.165.213 with SMTP id o204mr15483506ioe.10.1459091630441; Sun, 27 Mar 2016 08:13:50 -0700 (PDT) X-Received: by 10.50.136.167 with SMTP id qb7mr55531igb.7.1459091630419; Sun, 27 Mar 2016 08:13:50 -0700 (PDT) Path: csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!av4no2286953igc.0!news-out.google.com!pn7ni16988igb.0!nntp.google.com!nt3no5048204igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Sun, 27 Mar 2016 08:13:49 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.88.165.82; posting-account=Kjeg4goAAACdjmX7_q4DicLszBWtGtIs NNTP-Posting-Host: 87.88.165.82 References: <89a6c69e-5f60-47d7-99db-4004966fc7c5@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5f7ff60d-0297-4bee-b3e4-3af0ca757dfe@googlegroups.com> Subject: Re: Help with python script for NMR From: mohamadmaaz5@gmail.com Injection-Date: Sun, 27 Mar 2016 15:13:50 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:105850 On Sunday, March 27, 2016 at 4:50:01 PM UTC+2, Joel Goldstick wrote: > On Sun, Mar 27, 2016 at 10:38 AM, wrote: > > > Hello there, > > I found a python script in a scientific article that enables a simple > > calculation on an NMR spectrum. > > I have no experience in programming and i would appreciate it if i can > > communicate with someone who can write this script and send it to me by > > mail in py format. It's a short script but i keep making alot of mistaken > > and it fails every time. > > Anyone's interested in helping me ? > > Thanks > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > copy the code here. You will get help, but people don't generally write > programs for others here > > -- > Joel Goldstick > http://joelgoldstick.com/ > http://cc-baseballstats.info/ this is the script. the thing is that i have zero experience in writing and i cant find the error. all i need is to embed this script to perfome a relatively simple calculation on a spectra. hope anyone can help. thanks #! /usr /bin/envpython #encoding:utf- 8 i m p o r tnmrtec . nmrNotebook . c o n t r o l l e r . C o n t r o l l e r as Cont i m p o r tnmrtec . u t i l as u t i l i m p o r tnmrtec . nmrNotebook . model . common .nmrCommon as nmrcom c l a s sBarycentre : """ computesthebarycenterofeach definedr e c t a n g l eanddeducesthe p o l y d i s p e r s i t yindexofthes o l u t i o n """ d e fi n i t( s e l f ) : """ i n i t i a l i z e sandgetthei n t e g r a t i o ncoo rdin ates """ df =1.86#tobechangedf o reachtypeof... ... molecule f r o mNNBlibimportDialogText , l i s t O f R e c t a n g l e s s e l f . d a t a = NNB . l o a d C u r r e n t D a t a ( ) i f( getdim () != 2 ) : s e l f . die (" Tobeappliedon2Donly" ) i flen ( listOfRectangles () ) == 1 : s e l f . die (" Youmustaddarectangletodefineazoomregion. " ) i flen ( listOfRectangles () )>2 : s e l f . die (" expectedtwozoomregion. %dzoomregionsweredefined. " % ... ...len ( listOfRectangles () ) ) f o riin[ 0 , 1 ] : indexRect = listOfRectangles () [ i ] dim (2) s e l f . F1Left = int ( indexRect [ 0 ] ) s e l f . F1Right = int ( indexRect [ 2 ] ) s e l f . F2Left = int ( indexRect [ 1 ] ) s e l f . F2Right = int ( indexRect [ 3 ] ) i fi==0 : b = s e l f . pointToDamping ( s e l f . barycenter () ) b = b* *(- df ) else: a = s e l f . pointToDamping ( s e l f . barycenter () ) a = a * *(- df ) ip=a/b i fip<1.0: ip= 1/ ip r e s u l t=" p o l y d i s p e r s i t yindex: %s" %ip DialogText (" Resultat" , r e s u l t ) #--------------------------------------------------------------------------- defpointToDamping ( s e l f , value ) : " " " p o i n t T o D a m p i n gc o n v e r t sp o i n t su n i t si n t od i f f u s i o nu n i t s """ c = Cont . getCurrentControllerDeDocument ( ) f o l d = c . getCurrentNMRFolder ( ) nsa = f o l d . getNNBNMRSpectrum ( ) . getAxisF ( 1 ) p r i n tvalue newdamping = u t i l . NMRUnitToolKit . pointToUnit (nmrcom . NMRUnit . ... ...UNITDAMPING, nsa , value ) r e t u r nnewdamping #--------------------------------------------------------------------------- d e fbarycenter ( s e l f ) : """ r e a l i z ethei n t e g r a t i o noverthei n t e g r a t i o nzones (obtainedati n i t i a l i z a t i o n) """ #i n i t i a l i s a t i o ndud a t a b u f f e razero dim ( 1 ) zero ( ) put (" data" ) #onmetl apremierecolonne dim ( 2 ) c o l ( i n t ( s e l f . F2Left ) ) dim ( 1 ) put (" data" ) f o rcolumninrange ( s e l f . F2Left +1, s e l f . F2Right +1) : dim ( 2 ) c o l ( i n t ( column ) ) dim ( 1 ) a d d d a t a ( ) p u t (" data" ) dim(1) get (" data" ) m=0 n=0 f o riinrange ( s e l f . F1Left , s e l f . F1Right+1) : m += float ( val1d ( i ) )*i n += float ( val1d ( i ) ) b = m/n returnb #thenexecute Barycentre () i fname==" main" : try: Barycentre () except: fromNNBlibimportalert , formatExceptionInfo try: alert ( formatExceptionInfo () ) except: raise" shouldneverhappen"