0

I ran a Python code and here is the full code as follows :

    import MDAnalysis as mda
    import matplotlib.pyplot as plt
    %matplotlib inline
    u = mda.Universe('nptmd.tpr','nptmd.xtc')
    H = u.select_atoms('byres(name OW HW1 HW2)')
    A = u.select_atoms('byres(name OW HW1 HW2)')
    D = u.select_atoms('byres(name OW HW1 HW2)')
    hb_ac = hbonds.HydrogenBondAutoCorrel(u, acceptors=A, hydrogens=H, donors=D,bond_type='continuous',sample_time=5,nruns=20000,nsamples=10,pbc=True,angle_crit=130.0, dist_crit=3.0)
    hb_ac.run()
    hb_ac.solve()
    time = hb_ac.solution['time']
    results = hb_ac.solution['results']
    tau = hb_ac.solution['tau']
    fit=hb_ac.solution['fit']
    estimate = hb_ac.solution['estimate']
    print("{time} {results}".format(time=time,results=results))
    print("{time} {estimate}".format(time=time,estimate=estimate))
    plt.figure(1,figsize=(15, 5))
    plt.figure(1,figsize=(15, 5))
    plt.subplot(122)
    plt.xlabel('time')
    plt.ylabel('HBLc')
    plt.title('HBL Continuos')
    plt.plot(time,results, 'ro')
    plt.plot(time,estimate)
    plt.show()
    print (tau)

The results I am getting as:-

[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4.] [1.0000000e+00 5.2790266e-01 3.2588491e-01 2.1265593e-01 1.4223534e-01 9.6894175e-02 6.6584438e-02 4.6033673e-02 3.1977266e-02]

But I want the results as:

0.  1.0000000e+00

0.5 5.2790266e-01

1.  3.2588491e-01 

1.5 2.1265593e-01

2.  1.4223534e-01

2.5 9.6894175e-02

3.  6.6584438e-02

3.5 4.6033673e-02

4.  3.1977266e-02

How can I get the output as the above one..?

Any suggestions are highly appreciated.

4
  • 2
    What you have is not a dictionary; it is a list of lists. I suggest you to read the documentation on zip() function to transpose it into a format that you can use. Commented May 3, 2018 at 3:45
  • Yes, I want the results in the latter format. So any suggestions... Commented May 3, 2018 at 3:50
  • Yes, my suggestion is to read the documentation. If you want a more specific answer you should post your actual code, especially the part that generates tau. Commented May 3, 2018 at 4:45
  • I have now edited the code, and i have now put the actual full code in the question. Commented May 3, 2018 at 5:13

1 Answer 1

1

This shows how to print a list of lists:

a = [ [1, 2, 3, 4], [11, 12, 13, 14]]

# as tuples
for row in zip(a[0], a[1]):
    print row 

# as formated output
for row in zip(a[0], a[1]):
    print "{} {}".format(*row)

If you want your exact data structure to be used post a minimal code that can just run without any modification or external data.

Sign up to request clarification or add additional context in comments.

1 Comment

I am getting the values as [0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0] [1.0000000e+00 5.2790266e-01 3.2588491e-01 ...] but i want the values as: 0.0 1.0000000e+00 0.5 5.2790266e-01 1.0 3.2588491e-01 1.5 2.1265593e-01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.