Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created August 4, 2015 19:39
Show Gist options
  • Save leelasd/8b4b0b3431126e2c68b1 to your computer and use it in GitHub Desktop.
Save leelasd/8b4b0b3431126e2c68b1 to your computer and use it in GitHub Desktop.
############################################
def read_mols(fname):
mol = molecule('Water')
for line in fname:
ats,x,y,z=line.split()
at=atom(ats,float(x),float(y),float(z))
mol.addatom(at)
return(mol)
############################################
class atom:
def __init__(self,atno,x,y,z):
self.atno = atno
self.position = (x,y,z)
def symbol(self): # a class method
return Atno_to_Symbol[atno]
def __repr__(self): # overloads printing
return '%s %10.4f %10.4f %10.4f' %(self.atno, self.position[0],
self.position[1],self.position[2])
############################################
class molecule:
def __init__(self,name='Generic'):
self.name = name
self.atomlist = []
def addatom(self,atom):
self.atomlist.append(atom)
def __repr__(self):
str = ' %d \n' % len(self.atomlist)
str = str +'This is a molecule named %s\n' % self.name
for atom in self.atomlist:
str = str + `atom` + '\n'
return str
############################################
@namnguyendsn
Copy link

namnguyendsn commented Jul 11, 2018

hi,
are you understand this str = str + atom + '\n'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment