user11847849
user11847849

Reputation:

How to print selected numbers from a list in python?

I want to print all atoms except H (hydrogen) from the pdb file. Here is the file

https://github.com/mahesh27dx/molecular_phys.git

Following code prints the objects of the file

import numpy as np
import mdtraj as md

coord = md.load('alanine-dipeptide-nowater.pdb')
atoms, bonds = coord.topology.to_dataframe()
atoms

The result looks like this enter image description here

From this table I want to print all the elements except H . I think it can be done in python using the list slicing. Could someone have any idea how it can be done? Thanks!

Upvotes: 0

Views: 69

Answers (2)

Robby the Belgian
Robby the Belgian

Reputation: 663

You probably should clarify that you want help with mdtraj or pandas specifically.

Anyway, it's as simple as atoms.loc[atoms.element != 'H'].

Upvotes: 2

IoaTzimas
IoaTzimas

Reputation: 10624

You can do the following:

print(*list(df[df.element!='H']['element']))

If you want the unique elements, you can do this:

print(*set(df[df.element!='H']['element']))

Upvotes: 0

Related Questions