On Sunday, March 27, 2016 at 4:50:01 PM UTC+2, Joel Goldstick wrote: > On Sun, Mar 27, 2016 at 10:38 AM, <mohamadma...@gmail.com> 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://joelgoldstick.com/stats/birthdays> > 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" -- https://mail.python.org/mailman/listinfo/python-list