def findRelatedBySym( this, tol=1e-1 ): print "FIND ATOMS RELATED BY SYMMETRY" print "------------------------------" print " TOLERANCE = ", tol if( len( this.symmetryOperators ) == 0 ): print " ## ERROR ##: The molecule have not symmetry operators" return print "" symGrp = 0 for atom in this: if( atom.real ): atom.symGrp = symGrp print " ", "%5d"%atom.id, "--> [", for p in this.symmetryOperators: xyz = atom.xyzMatrix()*p.rotation.transpose()+numpy.matrix( p.translation ) proyectedAtom = Atom( xyz[0,0], xyz[0,1], xyz[0,2], label=atom.label, charge=atom.charge, id=atom.id ) for atom2 in this: r = numpy.sqrt( sum( (atom2.xyzArray()-proyectedAtom.xyzArray())**2 ) ) if( r < tol ): atom2.symGrp = symGrp print atom2.id, print "]" symGrp += 1 this.nSymGrp = symGrp print ""
def checkSymmetry( this, tol=1e-1, force=False ): print "SYMMETRY CHECKING" print "-----------------" print " TOLERANCE = ", tol print " FORCE SYMMETRY = ", force if( len( this.symmetryOperators ) == 0 ): print " Skipping check, because the molecule have not symmetry operators" return isSymmetric = True for atom in this: for p in this.symmetryOperators: xyz = atom.xyzMatrix()*p.rotation.transpose()+numpy.matrix( p.translation ) proyectedAtom = Atom( xyz[0,0], xyz[0,1], xyz[0,2], label=atom.label, charge=atom.charge, id=atom.id ) for atom2 in this: r = numpy.sqrt( sum( (atom2.xyzArray()-proyectedAtom.xyzArray())**2 ) ) if( r < tol and r > Atom.xyzThresholdComparison ): print " Is possible that this atoms are equivalent:" print " "+str(atom2) print " "+str(proyectedAtom) isSymmetric = False if( force ): print " Forced to satisfy the symmetry !!!" atom2.set( x=proyectedAtom.x, y=proyectedAtom.y, z=proyectedAtom.z ) if( force ): print " The molecule now is according with the symmetry operators" else: if( isSymmetric ): print " The molecule is according with the symmetry operators" else: print " The molecule is not according with the symmetry operators"