Created
August 4, 2015 19:39
-
-
Save leelasd/8b4b0b3431126e2c68b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################ | |
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 | |
############################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
are you understand this str = str +
atom
+ '\n'?