def receiveTarget(self): self.clientSock.send("receivingTarget") data = self.clientSock.recv(1024) self.clientSock.send("targetReceived") radecS = data.split(":") Ra = Angle(r=float(radecS[0])) Dec = Angle(r=float(radecS[1])) return [Ra, Dec]
def test_angle_class_hms_and_dms_must_be_consistent(): a = Angle(d=1) a.dms = (1, 1, 0, 0) assert a.hms.hms == (1, 0, 4, 0.0) a.hms = (1, 1, 0, 0) assert a.dms.dms == (1, 15, 0, 0.0)
def correct(self,Az,Alt): tVec = self.AzAltToVec(Az.r, Alt.r) tV = np.matrix([tVec]) dVec = self.rotationMatrix*tV.T [rAz, rAlt] = self.VecToAzAlt(dVec) aAz = Angle(r=rAz) aAlt = Angle(r=rAlt) return [aAz,aAlt]
def __init__(self, parent=None): super().__init__(parent) self.offset = 75 self.span = self.offset + 525 self.center = QPoint(self.span / 2, self.span / 2) self.setMinimumSize(self.span, self.span) self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.setMouseTracking(True) self.wedges = [] for start in range(0, 360 * 16, 45 * 16): self.wedges.append( CompassWedge( start, self.span, self.span, self.offset, Angle(floor(((360 - start / 16 + 45) % 360) / 45)), self)) deg_font = QFont("Consolas", 22, 2) for deg in range(8): temp = QLabel(self) angle = deg * 45 temp.setText(str(angle) + '°') temp.setFont(deg_font) tw = temp.fontMetrics().boundingRect(temp.text()).width() th = temp.fontMetrics().boundingRect(temp.text()).height() temp.move(self.deg_lbl_pos((180 - angle) % 360, QSize(tw, th)))
def __init__(self, upCalibration, downCalibration): self.upCalibration = upCalibration self.downCalibration = downCalibration self.lastPosition = Angle(d=0) self.ascending = True self.voltageRecord = [0, 0] self.buffer = 0.0002
def voltageToAngle(self, volts): power = 0 degrees = 0 for c in reversed(self.coeficients): degrees += math.pow(volts, power) * c power += 1 return (Angle(d=degrees))
def test_angle_class_getting_hms_property_must_work(): a = Angle(d=45.0) assert a.hms.sign == 1 assert a.hms.hh == 3.0 assert a.hms.mm == 0.0 assert a.hms.ss == 0.0 assert a.hms.hms == (1, 3, 0.0, 0.0) assert str(a.hms) == ("+03HH 00MM 00.000SS") a = Angle(sg="-12h14m13.567s") assert a.hms.sign == -1 assert a.hms.hh == 12 assert a.hms.mm == 14 assert a.hms.ss == 13.567 assert a.hms.hms == (-1, 12, 14, 13.567) assert str(a.hms) == "-12HH 14MM 13.567SS"
def test_angle_class_getting_dms_property_must_work(): a = Angle(d=45.0) assert a.dms.sign == 1 assert a.dms.dd == 45.0 assert a.dms.mm == 0.0 assert a.dms.ss == 0.0 assert a.dms.dms == (1, 45, 0.0, 0.0) assert str(a.dms) == ("+45DD 00MM 00.000SS") a = Angle(sg="-12h14m13.567s") assert a.dms.sign == -1 assert a.dms.dd == 183 assert a.dms.mm == 33 assert a.dms.ss == 23.505 assert a.dms.dms == (-1, 183, 33, 23.505) assert str(a.dms) == "-183DD 33MM 23.505SS"
def test_angle_class_setting_hms_property_must_work(): a = Angle(d=0.0) a.hms = (1, 12, 14, 13.567) v = 12 + 14 / 60.0 + 13.567 / 3600.0 assert a.h == v assert a.hms.sign == 1 assert a.hms.hh == 12 assert a.hms.mm == 14 assert a.hms.ss == 13.567 assert str(a.hms) == "+12HH 14MM 13.567SS" a.hms.hh = 15 assert a.h == 15 + 14 / 60.0 + 13.567 / 3600.0 a.hms.mm = 15 assert a.h == 15 + 15 / 60.0 + 13.567 / 3600.0 a = Angle(d=0.0) a.hms.mm = 12 assert round(a.h, 15) == 12 / 60.0
def test_angle_class_setting_dms_property_must_work(): a = Angle(d=0.0) a.dms = (-1, 183, 33, 23.505) v = -1 * (183 + 33 / 60.0 + 23.505 / 3600.0) assert a.d == v assert a.dms.sign == -1 assert a.dms.dd == 183 assert a.dms.mm == 33 assert a.dms.ss == 23.505 assert str(a.dms) == "-183DD 33MM 23.505SS" a.dms.dd = 101 assert a.d == -101.55652916666668 a.dms.mm = 15 assert a.d == -101.25652916666667 a = Angle(d=0.0) a.dms.mm = 12 assert round(a.d, 15) == 12 / 60.0
def test_angle_class_setting_dms_property_must_work(): a = Angle(d=0.0) a.dms = (-1, 183, 33, 23.505) v = -1 * (183 + 33/60.0 + 23.505/3600.0) assert a.d == v assert a.dms.sign == -1 assert a.dms.dd == 183 assert a.dms.mm == 33 assert a.dms.ss == 23.505 assert str(a.dms) == "-183DD 33MM 23.505SS" a.dms.dd = 101 assert a.d == -101.55652916666668 a.dms.mm = 15 assert a.d == -101.25652916666667 a = Angle(d=0.0) a.dms.mm = 12 assert round(a.d, 15) == 12/60.0
def test_angle_class_setting_hms_property_must_work(): a = Angle(d=0.0) a.hms = (1, 12, 14, 13.567) v = 12 + 14/60.0 + 13.567/3600.0 assert a.h == v assert a.hms.sign == 1 assert a.hms.hh == 12 assert a.hms.mm == 14 assert a.hms.ss == 13.567 assert str(a.hms) == "+12HH 14MM 13.567SS" a.hms.hh = 15 assert a.h == 15 + 14/60.0 + 13.567/3600.0 a.hms.mm = 15 assert a.h == 15 + 15/60.0 + 13.567/3600.0 a = Angle(d=0.0) a.hms.mm = 12 assert round(a.h, 15) == 12/60.0
def test_angle_class_must_initialize_properly(): a = Angle(sg="12h14m13.567s") val = 12 + 14 / 60.0 + 13.567 / 3600.0 assert a.h == val assert a.ounit == 'hours' assert a.r == h2r(val) assert a.d == h2d(val) assert a.arcs == h2arcs(val) # ignore r with pytest.warns(UserWarning): Angle(sg="12h14m13.567s", r=10) a = Angle(sg="12h14m13.567s", r=10) assert a.r == h2r(val) assert a.ounit == 'hours' # ignore h and mm with pytest.warns(UserWarning): a = Angle(r=10, h=20) a = Angle(r=10, h=20) assert a.r == 10 assert a.ounit == 'radians' assert a.h == r2h(10) a = Angle(h=20, d=10) assert a.d == 10 assert a.ounit == 'degrees' assert a.h == d2h(10)
def loadProjParams(projName): """ This function loads projections.txt file, which includes different projections with their correspoding parameters. A sample raw of this file has the following format: TM3-EAST, TM, BESSEL, 0.9999, 34, 26:42:58.815, 200000, 0 where each comma delimited value corresponds to: projID, projFamily, ellipsoid, scale, lat0, lon0, falseEasting, falseNorthing respectively. It should be stated here that lat0, lon0 are defined in degrees (dms format, e.g. -0:23:9.01239573) within file. Arguments projName: string that specifies projection's ID, could be one of the followings: 'TM3-WEST', 'TM3-CENTRAL', 'TM3-EAST', 'TM87', 'UTM-34N', 'UTM-35N', 'HATT', 'TM87-WGS84' * If user desires to add another projection has to modify projections.txt file following its header's instructions Returns dictionary of projection's parameters, i.e. {'projID': string, 'projFamily': string, 'ellipsoid': string, 'scale': number, 'lat0': number, 'lon0': number, 'falseEasting': number, 'falseNorthing': number} * values of dictionary could be None if they are missing from file * CAUTION. lat0, lon0 inserted as degrees in dms format but returned in radians """ with open("projections.txt") as fObj: readCSV = reader(fObj, delimiter=',') header = [value.strip() for value in next(readCSV)] projParams = dict.fromkeys(header) for line in readCSV: if line[0].strip() == projName: for key, value in zip(header, line): projParams[key] = value.strip() for key in ['scale', 'falseEasting', 'falseNorthing']: if projParams[key]: projParams[key] = float(projParams[key]) for key in ['lat0', 'lon0']: if projParams[key]: # projParams[key] = DMStoRads(projParams[key]) projParams[key] = Angle(projParams[key]) return projParams raise Exception("The projection you defined does not exist " "in projections.txt file")
def setAngleMenu(self, angleName): while (True): print "** Enter %s\n" % angleName print "** Use one of the following formats:" print "** Option 1: Degrees \"D\" e.g. 15.1275" print "** Option 2: Degrees:Minutes \"DD:M\" e.g. 15:7.65" print "** Option 3: Degrees:Minutes:Seconds \"DD:MM:SS\" e.g. 15:07:39" print "** %s:" % angleName uInput = raw_input() try: theAngle = Angle(uInput) return theAngle break except ValueError as e: print "There was an error in the angle value that you entered: %s" % e.message
def invTM(E, N, projection): """ geodetic values in radians ellipsoid of class Ellipsoid m0 scale factor E0, N0 false Easting, Northing in meters returns projected coordinates of a point in meters """ ellipsoid = projection.ellipsoid m0 = projection.m0 lat0 = projection.lat0.radians lon0 = projection.lon0.radians E0 = projection.E0 N0 = projection.N0 S = N / m0 lat = latFromMeridianLength(lat0, S, ellipsoid) t = tan(lat) hta2 = ellipsoid.ePrimeSquared * (cos(lat)**2) E = E - E0 W = sqrt(1 - ellipsoid.eSquared * (sin(lat))**2) N = ellipsoid.a / W Q = E / (m0 * N) M = ellipsoid.a * (1 - ellipsoid.eSquared) / (W**3) T10 = t / (2 * m0**2 * M * N) T11 = (t / (24 * m0**4 * M * N**3)) *\ (5 + (3 * t**2) + hta2 - (4 * hta2**2) - (9 * t**2 * hta2)) T12 = (t / (720 * m0**6 * M * N**5)) *\ (61 + (90 * t**2) + (45 * t**4) + (46 * hta2) - (252 * t**2 * hta2) - (3 * hta2**2) + (100 * hta2**3) - (66 * t**2 * hta2**2) - (90 * t**4 * hta2) + (88 * hta2**4) + (225 * t**4 * hta2**2) + (84 * t**2 * hta2**3) - (192 * t**2 * hta2**4)) T13 = (t / (40320 * m0**8 * M * N**7)) *\ (1385 + (3633 * t**2) + (4095 * t**4) + (1575 * t**6)) T14 = 1 / cos(lat) T15 = (1 + (2 * t**2) + hta2) / (6 * cos(lat)) T16 = (5 + (6 * hta2) + (28 * t**2) - (3 * hta2**2) + (8 * t**2 * hta2) + (24 * t**4) - (4 * hta2**3) + (4 * t**2 * hta2**2) + (24 * t**2 * hta2**3)) / (120 * cos(lat)) T17 = (61 + (66 * t**2) + (1320 * t**4) + (720 * t**6)) / 5040 lat = lat - (T10 * E**2) + (T11 * E**4) - (T12 * E**6) + (T13 * E**8) lon = lon0 + (T14*Q) - (T15 * Q**3) + (T16 * Q**5) - (T17 * Q**7) lat = Angle(lat) lat.angleType = 'dms' lon = Angle(lon) lon.angleType = 'dms' return lat, lon
def log_item(self, data): last_unlogged = self.timeout_timer.isActive() self.timeout_timer.start() src = self.sender() if type(src) is ActionsWidget: if self.exact_angle.has_valid(): if self.exact_angle.is_valid(): self.log_angle(self.exact_angle.calc_angle()) self.exact_angle.clear_state() if src.source is LogSource.SYSTEM: self.log_system(src.get_action(data)) if last_unlogged: self.update_temp_log() elif src.source is LogSource.EVENT: self.log_event(src.get_action(data)) elif type(src) is Compass: self.log_compass(Angle.to_string(data)) elif type(src) is ExactAngle: self.log_angle(str(data))
def test_angle_class_must_handle_assignments(): a = Angle(d=10.5) a.r = d2r(45.0) v = 45.0 assert a.r == d2r(v) assert a.h == d2h(v) assert a.arcs == d2arcs(v) assert a.ounit == 'degrees' v = 46.0 # assignment a.r = d2r(v) assert a.r == d2r(v) assert a.h == d2h(v) assert a.d == v assert a.arcs == d2arcs(v) assert a.ounit == 'degrees' # no change v = 49.0 a.d = v assert a.r == d2r(v) assert a.h == d2h(v) assert a.d == v assert a.arcs == d2arcs(v) assert a.ounit == 'degrees' # no change v = 10 a.h = v assert a.r == h2r(v) assert a.h == v assert a.d == h2d(v) assert a.arcs == h2arcs(v) assert a.ounit == 'degrees' # no change v = 3600.0 a.arcs = v assert a.r == arcs2r(v) assert a.h == arcs2h(v) assert a.d == arcs2d(v) assert a.arcs == v assert a.ounit == 'degrees' # no change
def ECEFtoGeodetic(X, Y, Z, ellipsoid): """ X, Y, Z in meters ellipsoid: class ellipsoid returns Geodetic lat, lon in Angle and h in meters """ lon = atan2(Y, X) P = sqrt(X**2 + Y**2) lat0 = atan2((Z * (1 + ellipsoid.ePrimeSquared)), P) dlat = 1 while dlat > 10**-12: W = sqrt(1 - ellipsoid.eSquared * (sin(lat0))**2) N = ellipsoid.a / W lat = atan2((Z + ellipsoid.eSquared * N * sin(lat0)), P) dlat = abs(lat - lat0) lat0 = lat h = (Z / sin(lat)) - ((1 - ellipsoid.eSquared) * N) lat = Angle(lat) lat.angleType = 'dms' lon = Angle(lon) lon.angleType = 'dms' return lat, lon, h
def getLatLon(self): uLat = self.getGeneric('location', 'latitude') Lat = Angle(r=float(uLat)) uLon = self.getGeneric('location', 'longitude') Lon = Angle(r=float(uLon)) return [Lat,Lon]
def main(): """ This test shows various operators within Angle and AngleContainer classes. Shows memory management structure and access methods """ p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) # p4 = Particle([4.4, 4.4, 4.4], "C", 1.0, 2.34) # ptcl 1 p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # ptcl 2 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # ptcl 3 b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") # b3 = Bond(1, 2, 3.33, "hooke") b4 = Bond(2, 3, 4.44, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) # atoms2.put(p4) atoms2.put(p5) atoms2.put(p6) bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds2.put(b3) bonds2.put(b4) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 print "\n Cleaning memory for initial objects \n" print "angles1 container" print angles1 print " " print "angles2 container" print angles2 print "Testing 'in' operator (1 in angles1)" if (1 in angles1): print "angles1 contains gid 1" else: print "key not found in angles1" print "Testing 'in' operator (5 in angles1)" if (5 in angles1): print "angles1 contains gid 5" else: print "key not found in angles1" print " " angles1 += angles2 print "Will print the new angles1 after adding angles1 += angles2" print angles1 print "Check for pre-existing angle" if angles1.hasAngle([3, 2, 1]): print "angle 1--2--3 exists" else: print "angle 1--2--3 does NOT exists" print "Check for pre-existing angle" if angles1.hasAngle([2, 3, 1]): print "angle 2--3--1 exists" else: print "angle 2--3--1 does NOT exists"
def main(): """ Illustrates how a substructure method returns subgroup with ONLY particle container included This is for speed considerations """ print "**********************************************************************************************" print "Illustrates how a substructure method returns subgroup with ONLY particle container included" print "This is for speed considerations" print "**********************************************************************************************\n" p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([4.4, 4.4, 4.4], "Si", 1.0, 2.34) p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 1 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 2 p7 = Particle([7.7, 7.7, 7.7], "C", 1.0, 2.34) # 3 p8 = Particle([8.8, 8.8, 8.8], "C", 1.0, 2.34) # 4 b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") b3 = Bond(3, 4, 3.33, "hooke") b4 = Bond(4, 5, 4.44, "hooke") b5 = Bond(5, 6, 5.55, "hooke") b6 = Bond(6, 7, 6.66, "hooke") b7 = Bond(7, 8, 7.77, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") a2 = Angle(2, 3, 4, 2.22, "harmonic") a3 = Angle(3, 4, 5, 3.33, "harmonic") a4 = Angle(4, 5, 6, 4.44, "harmonic") a5 = Angle(5, 6, 7, 5.55, "harmonic") a6 = Angle(6, 7, 8, 6.66, "harmonic") d1 = Dihedral(1, 2, 3, 4, 1.11, "stiff") d2 = Dihedral(2, 3, 4, 5, 2.22, "stiff") d3 = Dihedral(3, 4, 5, 6, 3.33, "stiff") d4 = Dihedral(4, 5, 6, 7, 4.44, "stiff") d5 = Dihedral(5, 6, 7, 8, 5.55, "stiff") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) atoms1.put(p5) atoms1.put(p6) atoms1.put(p7) atoms1.put(p8) bonds = BondContainer() bonds.put(b1) bonds.put(b2) bonds.put(b3) bonds.put(b4) bonds.put(b5) bonds.put(b6) bonds.put(b7) angles = AngleContainer() angles.put(a1) angles.put(a2) angles.put(a3) angles.put(a4) angles.put(a5) angles.put(a6) dihedrals = DihedralContainer() dihedrals.put(d1) dihedrals.put(d2) dihedrals.put(d3) dihedrals.put(d4) dihedrals.put(d5) del p1, p2, p3, p4, p5, p6, p7, p8 del b1, b2, b3, b4, b5, b6, b7 del a1, a2, a3, a4, a5, a6 del d1, d2, d3, d4, d5 polymer1 = StructureContainer(atoms1, bonds, angles, dihedrals) del atoms1, bonds, angles, dihedrals print "********************************************************** \n" print "polymer1 Structure before returning sub-structure" print polymer1 print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubParticleContainer([2,3,4])" print " currently ID's are reassigned in substructure \n" subPtclC = polymer1.getSubStructure([2, 3, 4], particlesOnly=True) print subPtclC print "********************************************************** \n"
def read_lmpdata( strucC , parmC , data_file): """ Read Lammps data file Arguments: strucC (StructureContainer) parmC (ParameterContainer) data_file (str) data file ReturnS: strucC (StructureContainer) parmC (ParameterContainer) """ debug = 0 verbose = True set_chain_numbers = True if( not set_chain_numbers ): print " Warning not reading in chain numbers!!! " # Load periodic table pt = periodictable() F = open(data_file , 'r' ) lines = F.readlines() F.close() # # Read in data header with number of parameters # for line in lines: col = line.split() if ( len(col) >=2 ): # Read in number of each topolgical component if( col[1] == "atoms" ): n_atoms = int( col[0] ) elif( col[1] == "bonds" ): n_bonds = int( col[0] ) elif( col[1] == "angles" ): n_angles = int( col[0] ) elif( col[1] == "dihedrals" ): n_dihedrals = int( col[0] ) elif( col[1] == "impropers" ): n_impropers = int( col[0] ) if ( len(col) >= 3 ): # Read in number of each parameter type if( col[1] == "atom" and col[2] == "types" ): n_atypes = int( col[0] ) elif( col[1] == "bond" and col[2] == "types" ): n_btypes = int( col[0] ) elif( col[1] == "angle" and col[2] == "types" ): n_angtypes = int( col[0] ) elif( col[1] == "dihedral" and col[2] == "types" ): n_dtypes = int( col[0] ) elif( col[1] == "improper" and col[2] == "types" ): n_imptypes = int( col[0] ) # Read in box size if ( len(col) >= 4 ): if( col[2] == "xlo" and col[3] == "xhi" ): strucC.latvec[0][0] = float( col[1] ) - float( col[0] ) if( col[2] == "ylo" and col[3] == "yhi" ): strucC.latvec[1][1] = float( col[1] ) - float( col[0] ) if( col[2] == "zlo" and col[3] == "zhi" ): strucC.latvec[2][2] = float( col[1] ) - float( col[0] ) # Prind debug if( verbose ): print " atoms ",n_atoms print " n_bonds ",n_bonds print " n_angles ",n_angles print " n_dihedrals ",n_dihedrals print " n_impropers ",n_impropers print "" print "n_atom_types",n_atypes print "n_bond_types",n_btypes print "n_angle_types",n_angtypes print "n_dihedral_types",n_dtypes print "n_imp_dihedral_types",n_imptypes # Check to see if a previous read has occured pt_overwrite = False if( len(strucC.ptclC) > 0 ): pt_overwrite = True # Check of conistent number of atoms if( pt_overwrite ): if( len(strucC.ptclC) != n_atoms): print " %d atoms in passed structure "%(len(strucC.ptclC)) print " %d atoms in data file "%(n_atoms) sys.exit(" Inconsistent number of atoms " ) else: # # Initialize particle container # for pid_i in range(n_atoms): pt_i = Particle( ) strucC.ptclC.put(pt_i) bonds_overwrite = False if( len(strucC.bondC) > 0 ): bonds_overwrite = True if( len(strucC.bondC) != n_bonds): print " %d bonds in passed structure "%(len(strucC.bondC)) print " %d bonds in data file "%(n_bonds) sys.exit(" Inconsistent number of bonds " ) angles_overwrite = False if( len(strucC.angleC) > 0 ): angles_overwrite = True if( len(strucC.angleC) != n_angles): print " %d angles in passed structure "%(len(strucC.angleC)) print " %d angles in data file "%(n_angles) sys.exit(" Inconsistent number of angles " ) dih_overwrite = False if( len(strucC.dihC) > 0 ): dih_overwrite = True if( len(strucC.dihC) != n_dihedrals): print " %d dihedrals in passed structure "%(len(strucC.dihC)) print " %d dihedrals in data file "%(n_dihedrals) sys.exit(" Inconsistent number of dihedrals " ) imp_overwrite = False if( len(strucC.impC) > 0 ): imp_overwrite = True if( len(strucC.impC) != n_impropers): print " %d impropers in passed structure "%(len(strucC.impC)) print " %d impropers in data file "%(n_impropers) sys.exit(" Inconsistent number of impropers " ) # # Intialize # - read in boolean to off # read_Masses = 0 read_Pair = 0 read_Bond_coeff = 0 read_Angle_coeff = 0 read_Dihedral_coeff = 0 read_Improper_coeff = 0 read_Atoms = 0 read_Bonds = 0 read_Angles = 0 read_Dihedrals = 0 read_Impropers = 0 # - lists as indecise can be out of order in data file ATYPE_REF = n_atypes*[""] ATYPE_MASS = np.zeros(n_atypes) ATYPE_EP = np.zeros(n_atypes) ATYPE_SIG = np.zeros(n_atypes) BTYPE_REF = n_btypes*[2*[""]] BONDTYPE_R0 = np.zeros(n_btypes) BONDTYPE_K = np.zeros(n_btypes) ANGTYPE_REF = n_angtypes*[3*[""]] ANGLETYPE_R0 = np.zeros(n_angtypes) ANGLETYPE_K = np.zeros(n_angtypes) DTYPE_REF = n_dtypes*[4*[""]] DIHTYPE_C = np.zeros((n_dtypes,4)) DIHTYPE_F = np.zeros(n_dtypes) DIHTYPE_K = np.zeros(n_dtypes) DIHTYPE_PN = np.zeros(n_dtypes) DIHTYPE_PHASE = np.zeros(n_dtypes) IMPTYPE_REF = n_imptypes*[4*[""]] IMPTYPE_F = np.zeros(n_imptypes) IMPTYPE_E0 = np.zeros(n_imptypes) IMPTYPE_K = np.zeros(n_imptypes) MOLNUMB = n_atoms*[0] ATYPE_IND = n_atoms*[0] CHARGES = np.zeros(n_atoms) R = n_atoms*[np.zeros(3)] ATYPE = n_atoms*[""] BONDS = n_bonds*[[0,0]] BTYPE_IND = n_bonds*[0] ANGLES = n_angles*[[0,0,0]] ANGTYPE_IND = n_angles*[0] DIH = n_dihedrals*[[0,0,0,0]] DTYPE_IND = n_dihedrals*[0] # # Check if values exist and need to be updated or don't and need to be created # ljtyp_update = False ljtyp_cnt = 0 if( len(parmC.ljtypC) > 0 ): print " LJ types will be updated " ljtyp_update = True btyp_update = False btyp_cnt = 0 if( len(parmC.btypC) > 0 ): print " Bond types will be updated " btyp_update = True atyp_update = False atyp_cnt = 0 if( len(parmC.atypC) > 0 ): print " Angle types will be updated " atyp_update = True dtyp_update = False dtyp_cnt = 0 if( len(parmC.dtypC) > 0 ): print " Dihedral types will be updated " dtyp_update = True imptyp_update = False imptyp_cnt = 0 if( len(parmC.imptypC) > 0 ): print " Improper dihedrals types will be updated " imptyp_update = True # # Read in data parameters # for line in lines: col = line.split() if( read_Masses and len(col) >= 2 ): cnt_Masses += 1 ind = int(col[0]) - 1 ATYPE_MASS[ind] = float(col[1]) if( len(col) >= 4 ): ATYPE_REF[ind] = col[3] ptype1 = col[3] else: ATYPE_REF[ind] = "??" ptype1 = "??" mass_i = float(col[1]) if( ljtyp_update ): ljtyp_cnt = ind + 1 if( ljtyp_cnt > len(parmC.ljtypC) ): print "Mass index %d larger then length of previously read ljtypC %d"%(ind,len(parmC.ljtypC)) ljtyp_i = parmC.ljtypC[ljtyp_cnt] ljtyp_i.setmass(mass_i) else: ljtyp_i = ljtype(ptype1) ljtyp_i.setmass(mass_i) parmC.ljtypC.put(ljtyp_i) # Turn of mass read if(cnt_Masses == n_atypes ): read_Masses = 0 if( read_Pair and len(col) >= 3 ): cnt_Pair += 1 ind = int(col[0]) - 1 ATYPE_EP[ind] = float(col[1]) ATYPE_SIG[ind] = float(col[2]) epsilon = float(col[1]) sigma = float(col[2]) ljtyp_ind = int(col[0]) ljtyp_i = parmC.ljtypC[ljtyp_ind] ljtyp_i.setparam(epsilon,sigma) # Turn pair parameter read off if(cnt_Pair >= n_atypes ): read_Pair = 0 if( read_Bond_coeff and len(col) >= 3 ): cnt_Bond_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) b_ind = int( col[0]) - 1 if( b_ind > n_btypes ): error_line = " Error in data file index of bond parameter exceeds number of bond parameters specified with bond types " sys.exit(error_line) BTYPE_REF[b_ind][0] = "??" BTYPE_REF[b_ind][1] = "??" BONDTYPE_K[b_ind] = float(col[1]) BONDTYPE_R0[b_ind] = float(col[2]) ptype1 = "??" ptype2 = "??" lmpindx = int( col[0]) kb = float(col[1]) r0 = float(col[2]) btype = "harmonic" g_type = 1 if( btyp_update ): btyp_cnt = b_ind + 1 btyp_i = parmC.btypC[btyp_cnt] btyp_i.setharmonic(r0,kb) btyp_i.set_g_indx(g_type) btyp_i.set_lmpindx(lmpindx) else: btyp_i = bondtype(ptype1,ptype2,btype) btyp_i.setharmonic(r0,kb) btyp_i.set_g_indx(g_type) btyp_i.set_lmpindx(lmpindx) parmC.btypC.put(btyp_i) if( cnt_Bond_coeff >= n_btypes ): read_Bond_coeff = 0 if( read_Angle_coeff and len(col) >= 3 ): cnt_Angle_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) a_ind = int( col[0]) - 1 if( a_ind > n_angtypes ): print sys.exit(" Error in data file index of angle parameter exceeds number of angle parameters specified with angle types ") ANGTYPE_REF[a_ind][0] = "??" ANGTYPE_REF[a_ind][1] = "??" ANGTYPE_REF[a_ind][2] = "??" ANGLETYPE_K[a_ind] = float(col[1]) ANGLETYPE_R0[a_ind] = float(col[2]) ptype1 = "??" ptype2 = "??" ptype3 = "??" lmpindx = int( col[0]) theta0 = float( col[2] ) # degrees kb = float( col[1] ) atype = "harmonic" gfunc_type = 1 if( atyp_update ): atyp_cnt = a_ind + 1 atyp_i = parmC.atypC[atyp_cnt] atyp_i.set_g_indx(gfunc_type) atyp_i.set_lmpindx(lmpindx) atyp_i.setharmonic(theta0,kb) else: atyp_i = angletype(ptype1,ptype2,ptype3,atype) atyp_i.set_g_indx(gfunc_type) atyp_i.set_lmpindx(lmpindx) atyp_i.setharmonic(theta0,kb) parmC.atypC.put(atyp_i) if( cnt_Angle_coeff >= n_angtypes ): read_Angle_coeff = 0 if( read_Dihedral_coeff and len(col) >= 3 ): cnt_Dihedral_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) d_ind = int( col[0]) - 1 if( debug): print " reading dih type ",d_ind," cnt ",cnt_Dihedral_coeff," of ",n_dtypes if( d_ind > n_dtypes ): error_line = " Error in data file index of dihedral parameter %d exceeds number of dihedral parameters %d "%(d_ind , n_dtypes) error_line += " specified with dihedral types " print sys.exit(error_line) DTYPE_REF[d_ind][0] = "??" DTYPE_REF[d_ind][1] = "??" DTYPE_REF[d_ind][2] = "??" DTYPE_REF[d_ind][3] = "??" # Assume OPLS dihedral type DIHTYPE_F[d_ind] = 3 DIHTYPE_C[d_ind][0] = float(col[1]) DIHTYPE_C[d_ind][1] = float(col[2]) DIHTYPE_C[d_ind][2] = float(col[3]) DIHTYPE_C[d_ind][3] = float(col[4]) ptype1 = "??" ptype2 = "??" ptype3 = "??" ptype4 = "??" # Set parameters according to type gfunc_type = 3 dtype = "opls" lmpindx = int( col[0] ) k1 = float( col[1] ) k2 = float( col[2] ) k3 = float( col[3] ) k4 = float( col[4] ) if( dtyp_update ): dtyp_cnt = d_ind + 1 dtyp_i = parmC.dtypC[dtyp_cnt] dtyp_i.set_g_indx(gfunc_type) dtyp_i.set_lmpindx(lmpindx) dtyp_i.setopls(k1,k2,k3,k4) else: dtyp_i = dihtype(ptype1,ptype2,ptype3,ptype4,dtype) dtyp_i.set_g_indx(gfunc_type) dtyp_i.set_lmpindx(lmpindx) dtyp_i.setopls(k1,k2,k3,k4) parmC.dtypC.put(dtyp_i) if( cnt_Dihedral_coeff >= n_dtypes ): read_Dihedral_coeff = 0 if( read_Improper_coeff and len(col) >= 3 ): cnt_Improper_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) imp_ind = int( col[0]) - 1 if( debug): print " reading imp dih type ",imp_ind," cnt ",cnt_Improper_coeff," of ",n_imptypes if( imp_ind > n_imptypes ): error_line = " Error in data file index of improper parameter %d exceeds number of improper parameters %d "%(imp_ind , n_imptypes) error_line += " specified with dihedral types " print sys.exit(error_line) IMPTYPE_REF[imp_ind][0] = "??" IMPTYPE_REF[imp_ind][1] = "??" IMPTYPE_REF[imp_ind][2] = "??" IMPTYPE_REF[imp_ind][3] = "??" # Assume OPLS dihedral type IMPTYPE_F[imp_ind] = 2 KE = float(col[1]) Eo = float(col[2]) IMPTYPE_E0[imp_ind] = Eo IMPTYPE_K[imp_ind] = KE ptype1 = "??" ptype2 = "??" ptype3 = "??" ptype4 = "??" # Set parameters according to type g_indx = 2 dtype = "improper" lmpindx = int( col[0] ) if( imptyp_update ): imptyp_cnt = imp_ind + 1 imptyp_i = parmC.imptypC[imptyp_cnt] imptyp_i.set_g_indx(g_indx) imptyp_i.setimp(Eo,KE) imptyp_i.set_lmpindx(lmpindx) else: imptyp_i = imptype(ptype1,ptype2,ptype3,ptype4,dtype) imptyp_i.set_g_indx(g_indx) imptyp_i.setimp(Eo,KE) imptyp_i.set_lmpindx(lmpindx) parmC.imptypC.put(imptyp_i) if( cnt_Improper_coeff >= n_imptypes ): read_Improper_coeff = 0 if( read_Atoms and len(col) >= 7 ): cnt_Atoms += 1 ind = int( col[0]) - 1 if( ind > n_atoms ): print sys.exit(" Error in data file index of atoms exceeds number of atoms specified with atoms ") chain_i = int(col[1]) lmptype_i = int(col[2]) #- 1 indx = int(col[2]) - 1 q_i = float(col[3]) m_i = ATYPE_MASS[indx] fftype_i = ATYPE_REF[indx] el = pt.getelementWithMass(m_i) if( el.symbol == "VS" ): el.symbol = ATYPE_l[atom_indx].strip() fftype_i = "VS" m_i = 0.0 # HACK !! if( ATYPE_MASS[indx] == 9.0 ): el.symbol = "LP" fftype_i = "LP" m_i = 0.0 r_i = [ float(col[4]),float(col[5]),float(col[6])] type_i = str(lmptype_i) #tagsD = {"chain":chain_i,"symbol":el.symbol,"number":el.number,"mass":el.mass,"cov_radii":el.cov_radii,"vdw_radii":el.vdw_radii} #if( pt_overwrite ): pt_i = strucC.ptclC[ind+1] pt_i.position = r_i update_coord = True if( not update_coord ): pt_i.type = el.symbol pt_i.charge = q_i pt_i.mass = m_i add_dict = pt_i.tagsDict # Set properties read in data file if( set_chain_numbers ): add_dict["chain"] = chain_i add_dict["symbol"] = el.symbol add_dict["number"] = el.number add_dict["mass"] = el.mass add_dict["cov_radii"] = el.cov_radii add_dict["vdw_radii"] = el.vdw_radii add_dict["lmptype"] = lmptype_i add_dict["fftype"] = fftype_i # add_dict["ffmass"] = ATYPE_MASS[indx] add_dict["residue"] = chain_i add_dict["qgroup"] = chain_i add_dict["resname"] = "MOLR" add_dict["ring"] = 0 add_dict["label"] = add_dict["symbol"] pt_i.setTagsDict(add_dict) if( cnt_Atoms >= n_atoms ): read_Atoms = 0 if(read_Bonds and len(col) >= 4 ): cnt_Bonds += 1 ind = int( col[0]) - 1 if( ind > n_bonds ): print sys.exit(" Error in data file index of bonds exceeds number of bonds specified with bonds ") BTYPE_IND[ind] = int(col[1] ) - 1 BONDS[ind] = [int(col[2]) - 1 , int(col[3]) - 1 ] i_o = int(col[2]) j_o = int(col[3]) if( bonds_overwrite ): bondObj = strucC.bondC[cnt_Bonds] bondObj.pgid1 = i_o bondObj.pgid2 = j_o bondObj.set_lmpindx(int(col[1] )) else: bondObj = Bond( i_o, j_o ) bondObj.set_lmpindx(int(col[1] )) strucC.bondC.put(bondObj) if( cnt_Bonds >= n_bonds ): read_Bonds = 0 if(read_Angles and len(col) >= 5 ): cnt_Angles += 1 ind = int( col[0]) - 1 ANGTYPE_IND[ind] = int(col[1] ) - 1 ANGLES[ind] = [int(col[2]) - 1, int(col[3]) - 1, int(col[4]) - 1 ] k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) if( cnt_Angles >= n_angles ): read_Angles = 0 if( angles_overwrite ): angleObj = strucC.angleC[cnt_Angles] angleObj.pgid1 = k_o angleObj.pgid2 = i_o angleObj.pgid3 = j_o angleObj.set_lmpindx(int(col[1] )) else: angleObj = Angle( k_o,i_o, j_o ) angleObj.set_lmpindx(int(col[1] )) strucC.angleC.put(angleObj) if(read_Dihedrals and len(col) >= 6 ): cnt_Dihedrals += 1 ind = int( col[0]) - 1 DTYPE_IND[ind] = int(col[1] ) - 1 DIH[ind] = [int(col[2]) - 1,int(col[3]) - 1, int(col[4]) - 1,int(col[5]) - 1] k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) l_o = int(col[5]) if( dih_overwrite ): dObj = strucC.dihC[cnt_Dihedrals] dObj.pgid1 = k_o dObj.pgid2 = i_o dObj.pgid3 = j_o dObj.pgid4 = l_o dObj.set_lmpindx(int(col[1] )) else: dObj = Dihedral( k_o,i_o, j_o,l_o ) dObj.set_lmpindx(int(col[1] )) strucC.dihC.put(dObj) if( cnt_Dihedrals >= n_dihedrals ): read_Dihedrals = 0 if(read_Impropers and len(col) >= 2 ): cnt_Impropers += 1 ind = int( col[0]) - 1 k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) l_o = int(col[5]) if( imp_overwrite ): impObj = strucC.impC[cnt_Impropers] impObj.pgid1 = k_o impObj.pgid2 = i_o impObj.pgid3 = j_o impObj.pgid4 = l_o impObj.set_lmpindx(int(col[1] )) impObj.set_type("improper") else: impObj = Improper( k_o,i_o, j_o,l_o ) impObj.set_lmpindx(int(col[1] )) impObj.set_type("improper") strucC.impC.put(impObj) if( cnt_Impropers >= n_impropers ): read_Impropers = 0 if ( len(col) >= 1 ): if( col[0] == "Masses" ): read_Masses = 1 cnt_Masses = 0 if( col[0] == "Atoms" ): read_Atoms = 1 cnt_Atoms = 0 if( col[0] == "Bonds" ): read_Bonds = 1 cnt_Bonds = 0 if( col[0] == "Angles" ): read_Angles = 1 cnt_Angles = 0 if( col[0] == "Dihedrals" ): read_Dihedrals = 1 cnt_Dihedrals = 0 if( col[0] == "Impropers" ): read_Impropers = 1 cnt_Impropers = 0 if ( len(col) >= 2 ): if( col[0] == "Pair" and col[1] == "Coeffs" ): read_Pair = 1 cnt_Pair = 0 if( col[0] == "Bond" and col[1] == "Coeffs" ): read_Bond_coeff = 1 cnt_Bond_coeff = 0 if( col[0] == "Angle" and col[1] == "Coeffs" ): read_Angle_coeff = 1 cnt_Angle_coeff = 0 if( col[0] == "Dihedral" and col[1] == "Coeffs" ): read_Dihedral_coeff = 1 cnt_Dihedral_coeff = 0 if( col[0] == "Improper" and col[1] == "Coeffs" ): read_Improper_coeff = 1 cnt_Improper_coeff = 0 # cnt_Bonds += 1 # ind = int( col[0]) - 1 # BTYPE_IND[ind] = int(col[1] ) - 1 # BONDS[ind][0] = int(col[2]) # if( cnt_Bonds >= n_atoms ): # read_Bonds = 0 # # if( ljtyp_update ): if( ljtyp_cnt != len(parmC.ljtypC) ): print " Number of LJ types read in %d does not match previously read %d "%(ljtyp_cnt,len(parmC.ljtypC)) if( debug): for ind in range(len(ATYPE_MASS)): print ind+1,ATYPE_MASS[ind] for ind in range(len(ATYPE_EP)): print ind+1,ATYPE_EP[ind],ATYPE_SIG[ind] for ind in range(n_btypes): print ind+1,BONDTYPE_R0[ind],BONDTYPE_K[ind] for ind in range(n_angtypes): print ind+1,ANGLETYPE_R0[ind],ANGLETYPE_K[ind] for ind in range(n_dtypes): print ind+1,DIHTYPE_C[ind] debug =0 if( debug): for ind in range(len(BONDS)): print ind+1,BONDS[ind] if(debug): sys.exit("debug 1 ") # # return (strucC,parmC)
def main(): """ This test shows compressing IDs when structureContainer has angles included """ p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([0.0, 0.0, 0.0], "Si", 1.0, 2.34) # p5 = Particle([4.4, 4.4, 4.4], "C", 1.0, 2.34) # 1 p6 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 2 p7 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 3 b1 = Bond(1, 3, 1.11, "hooke") b2 = Bond(3, 4, 2.22, "hooke") # b3 = Bond(1, 2, 3.33, "hooke") b4 = Bond(2, 3, 4.44, "hooke") a1 = Angle(1, 3, 4, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) # atoms2.put(p5) atoms2.put(p6) atoms2.put(p7) del atoms1[2] # remove 2nd particle so ID's are non-consecutive bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds2.put(b3) bonds2.put(b4) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) polymer1 = StructureContainer(atoms1, bonds1, angles1) polymer2 = StructureContainer(atoms2, bonds2, angles2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer2 += polymer1) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2 polymer2.compressPtclIDs() print "-------------------- After compressing --------------------" print "polymer2 = ", polymer2
import stellariumConnect, datetime, math from angles import Angle from twoStarCalibrate import twoStarCalibrate import numpy as np from configParser import calibrationParser stel1 = [Angle(r=1.6666*math.pi),Angle(r=math.pi/4)] stel2 = [Angle(r=-math.pi/1.1),Angle(r=math.pi/52)] tel1 = [Angle(r= -2.084132566391469),Angle(r= 0.785398163397448)] tel2 = [Angle(r= 2.390466410049688),Angle(r= 0.060415243338265)] TSC = twoStarCalibrate() TSC.addStar(tel1, stel1) TSC.addStar(tel2, stel2) R = TSC.twoStarRotationMatrix() R1 = TSC.oneStarRotaionMatrix() TSC.addRotationMatrix(R) [Az2,Alt2] = TSC.correct(-3.036725575684632, 0.300000000000000) calP = calibrationParser("instrumentCalibration.xml") calP.setAzAltCorrection(R) Rp = calP.getAzAltCorrection() print Rp print R print [Az2,Alt2]
def game_loop(self): global x, y, font, text, screen def clear(): screen.fill(BLACK) pygame.init() x = gtk.gdk.screen_width() y = gtk.gdk.screen_height() - 55 half_x = x / 2 half_y = y / 2 screen = pygame.display.get_surface() angleDisplay = screen.subsurface( (x * .18, y * .1, x - (2 * x * .18), y - (2 * y * .1))) self.planetNear = Image( PLANET_PREFIX + str(randint(0, PLANET_NUMBER - 1)) + PLANET_SUFFIX, screen) self.planetFar = Image( PLANET_PREFIX + str(randint(0, PLANET_NUMBER - 1)) + PLANET_SUFFIX, angleDisplay) # This is what a clicked button will call. so handle an answer here def saveAnswer(answer): # fill with black to wipe the screen. Otherwise the answer labels stack on each other # We wont need this when we are not outputting the answer. if (angle.checkAnswer(answer)): print('correct') score.increment() angle.setRandomAngle() print self.planetNear.image self.planetNear.originalImage = self.planetFar.originalImage self.planetFar = Image( PLANET_PREFIX + str(randint(0, PLANET_NUMBER - 1)) + PLANET_SUFFIX, angleDisplay) putPlanets(self.planetNear, self.planetFar) else: print('wrong') loseGame('') score.reset() def startGame(msg): global state state = GAME screen.fill(BLACK) def loseGame(msg): global state state = OVER clear() def mainMenu(msg): global state state = MAIN clear() def putPlanets(near, far): near.setSize(x * NEAR_SIZE, x * NEAR_SIZE) near.move(half_x, half_y) near.rect.center = near.rect.topleft far.setSize(x * FAR_SIZE, x * FAR_SIZE) far.move(angle.top[0], angle.top[1]) far.rect.center = far.rect.topleft pygame.display.set_caption('Angles') font = pygame.font.SysFont(None, 48) smallFont = pygame.font.SysFont(None, 30) clock = pygame.time.Clock() scoreDisplay = screen.subsurface( (x * SCORE_X, y * SCORE_Y, x - (x * SCORE_X), y - (y * SCORE_Y))) angle = Angle(angleDisplay, 150, _ypercent=.3) tux = Image(TUX_IMAGE, screen) tux.move(half_x, half_y) tux.rect.midbottom = tux.rect.topleft putPlanets(self.planetNear, self.planetFar) score = ScoreTicker(x, y, scoreDisplay) but_half = (x * BUT_W / 2) rightBut = Button("Right", x * B1_X, y * B1_Y, x * BUT_W, y * BUT_H, screen, saveAnswer) acuteBut = Button("Acute", x * B2_X, y * B2_Y, x * BUT_W, y * BUT_H, screen, saveAnswer) obtBut = Button("Obtuse", x * B3_X, y * B3_Y, x * BUT_W, y * BUT_H, screen, saveAnswer) #Game State Stuff startBut = Button("Start", (x * B4_X) - but_half, y * B4_Y, x * BUT_W, y * BUT_H, screen, startGame) mainBut = Button("Menu", (x * B5_X) - but_half, y * B5_Y, x * BUT_W, y * BUT_H, screen, mainMenu) restartBut = Button("Restart", (x * B6_X) - but_half, y * B6_Y, x * BUT_W, y * BUT_H, screen, startGame) mainText = font.render("Tux Explorer", True, WHITE, BLACK) mainHalfWidth = mainText.get_width() / 2 main_xpos = half_x - mainHalfWidth main_ypos = MAIN_Y * y helpText1 = smallFont.render( "Tux is lost! Help him navigate through space.", True, WHITE, BLACK) help1_xpos = half_x - (helpText1.get_width() / 2) help1_ypos = HELP1_Y * y helpText2 = smallFont.render( "Tell him if his angle to the next planet is acute, obtuse, or right.", True, WHITE, BLACK) help2_xpos = half_x - (helpText2.get_width() / 2) help2_ypos = HELP2_Y * y overText = font.render("Game Over!", True, WHITE, BLACK) overHalfWidth = overText.get_width() / 2 over_xpos = half_x - overHalfWidth over_ypos = OVER_Y * y global state state = MAIN while 1: while gtk.events_pending(): gtk.main_iteration() clicked = False for event in pygame.event.get(): if event.type == pygame.QUIT: # Change "Juego Finalizado" to change the exit message (log) score.saveScore() exit("Game Finalized") elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) elif event.type == pygame.MOUSEBUTTONUP: clicked = True if state == MAIN: screen.blit(mainText, (main_xpos, main_ypos)) screen.blit(helpText1, (help1_xpos, help1_ypos)) screen.blit(helpText2, (help2_xpos, help2_ypos)) startBut.draw(clicked) elif state == GAME: obtBut.draw(clicked) acuteBut.draw(clicked) rightBut.draw(clicked) score.draw() angle.draw() self.planetNear.draw() tux.draw() self.planetFar.draw() else: screen.fill(BLACK) screen.blit(overText, (over_xpos, over_ypos)) mainBut.draw(clicked) restartBut.draw(clicked) pygame.display.flip() # Try to stay at 30 FPS clock.tick(30)
def loadCoordsFile(fileName, clmsSpecification, dlm=','): """ This function loads a file that contains points along with their respective coordinates. A sample row of this file may have the following format: p4,4478329.405,1921444.508,4101378.606, 41.464, 42.651 where each delimited value corresponds to: id, E/X/lat, N/Y/lon, U/Z/h, geoidHeight, GMHeight respectively. and id: point id ENU: map coordinates XYZ: ECEF coordinates latlonh: geodetic coordinates geoidHeight: geoid undulation, i.e. geoidHeight = h - U GMHeight: geoid undulation coming from a geopotential model as EGM08 * All coordinates values expressed in meters, except lat, lon where their values could be radians or degrees in the following formats: decimal degrees-dd, e.g. -0.1927322, degrees:minutes-dm, e.g. 11:2.3474, degrees:minutes:seconds-dms, e.g. -0:59:59.0001123 Arguments fileName: string that specifies the name of file to be loaded clmsSpecification: list of strings, that specifies what each column represent and in what order the columns are layout. possible list any subset of: ['id', 'X', 'Y', 'Z', lat-r/dd/dm/dms, lon-r/dd/dm/dms, h, E, N, U, 'geoidHeight', 'GMHeight'] e.g. ['id', 'X', 'Y', 'Z'] or ['id', 'Z', 'Y', 'X', 'geoidHeight'] lat-r/dd/dm/dms means that it could be lat-r or lat-dd or lat-dm or lat-dms. The same holds for lon-r/dd/dm/dms dlm: one character string that specifies file's delimiter e.g. ' ', ',', '\t' Returns any possible subset (concerning keys) of the follwoing dictionary: {'id': [strings], 'X': [numbers], 'Y': [numbers], 'Z': [numbers], 'lat-r/dd/dm/dms': [numbers/strings], 'lon-r/dd/dm/dms': [numbers/strings], 'h': [numbers], 'E': [numbers], 'N': [numbers], 'U': [numbers] 'geoidHeight': [numbers], 'GMHeight': [numbers]} """ if len(set(clmsSpecification)) != len(clmsSpecification): raise Exception("Your columns specification contain duplicates") allClms = {'id', 'X', 'Y', 'Z', 'lat-r', 'lon-r', 'lat-dd', 'lon-dd', 'lat-dm', 'lon-dm', 'lat-dms', 'lon-dms', 'h', 'E', 'N', 'U', 'geoidHeight', 'GMHeight'} if not set(clmsSpecification).issubset(allClms): raise Exception("Define columns specification properly") with open(fileName) as fObj: readCSV = reader(fObj, delimiter=dlm) data = defaultdict(list) for line in readCSV: if line: for key, value in zip(clmsSpecification, line): data[key].append(value.strip()) latlonInDeg = ['lat-dd', 'lon-dd', 'lat-dm', 'lon-dm', 'lat-dms', 'lon-dms'] for key in set(data.keys()) - {'id'}: # if key not in latlonInDeg: # data[key] = [float(x) for x in data[key]] if key in ['lat-r', 'lon-r']: data[key] = [Angle(float(x)) for x in data[key]] elif key in latlonInDeg: data[key] = [Angle(x) for x in data[key]] else: data[key] = [float(x) for x in data[key]] return data
def read_lmpdata(strucC, parmC, data_file): """ Read Lammps data file Arguments: strucC (StructureContainer) parmC (ParameterContainer) data_file (str) data file ReturnS: strucC (StructureContainer) parmC (ParameterContainer) """ debug = 0 verbose = True set_chain_numbers = True if (not set_chain_numbers): print " Warning not reading in chain numbers!!! " # Load periodic table pt = periodictable() F = open(data_file, 'r') lines = F.readlines() F.close() # # Read in data header with number of parameters # for line in lines: col = line.split() if (len(col) >= 2): # Read in number of each topolgical component if (col[1] == "atoms"): n_atoms = int(col[0]) elif (col[1] == "bonds"): n_bonds = int(col[0]) elif (col[1] == "angles"): n_angles = int(col[0]) elif (col[1] == "dihedrals"): n_dihedrals = int(col[0]) elif (col[1] == "impropers"): n_impropers = int(col[0]) if (len(col) >= 3): # Read in number of each parameter type if (col[1] == "atom" and col[2] == "types"): n_atypes = int(col[0]) elif (col[1] == "bond" and col[2] == "types"): n_btypes = int(col[0]) elif (col[1] == "angle" and col[2] == "types"): n_angtypes = int(col[0]) elif (col[1] == "dihedral" and col[2] == "types"): n_dtypes = int(col[0]) elif (col[1] == "improper" and col[2] == "types"): n_imptypes = int(col[0]) # Read in box size if (len(col) >= 4): if (col[2] == "xlo" and col[3] == "xhi"): strucC.latvec[0][0] = float(col[1]) - float(col[0]) if (col[2] == "ylo" and col[3] == "yhi"): strucC.latvec[1][1] = float(col[1]) - float(col[0]) if (col[2] == "zlo" and col[3] == "zhi"): strucC.latvec[2][2] = float(col[1]) - float(col[0]) # Prind debug if (verbose): print " atoms ", n_atoms print " n_bonds ", n_bonds print " n_angles ", n_angles print " n_dihedrals ", n_dihedrals print " n_impropers ", n_impropers print "" print "n_atom_types", n_atypes print "n_bond_types", n_btypes print "n_angle_types", n_angtypes print "n_dihedral_types", n_dtypes print "n_imp_dihedral_types", n_imptypes # Check to see if a previous read has occured pt_overwrite = False if (len(strucC.ptclC) > 0): pt_overwrite = True # Check of conistent number of atoms if (pt_overwrite): if (len(strucC.ptclC) != n_atoms): print " %d atoms in passed structure " % (len(strucC.ptclC)) print " %d atoms in data file " % (n_atoms) sys.exit(" Inconsistent number of atoms ") else: # # Initialize particle container # for pid_i in range(n_atoms): pt_i = Particle() strucC.ptclC.put(pt_i) bonds_overwrite = False if (len(strucC.bondC) > 0): bonds_overwrite = True if (len(strucC.bondC) != n_bonds): print " %d bonds in passed structure " % (len(strucC.bondC)) print " %d bonds in data file " % (n_bonds) sys.exit(" Inconsistent number of bonds ") angles_overwrite = False if (len(strucC.angleC) > 0): angles_overwrite = True if (len(strucC.angleC) != n_angles): print " %d angles in passed structure " % (len(strucC.angleC)) print " %d angles in data file " % (n_angles) sys.exit(" Inconsistent number of angles ") dih_overwrite = False if (len(strucC.dihC) > 0): dih_overwrite = True if (len(strucC.dihC) != n_dihedrals): print " %d dihedrals in passed structure " % (len(strucC.dihC)) print " %d dihedrals in data file " % (n_dihedrals) sys.exit(" Inconsistent number of dihedrals ") imp_overwrite = False if (len(strucC.impC) > 0): imp_overwrite = True if (len(strucC.impC) != n_impropers): print " %d impropers in passed structure " % (len(strucC.impC)) print " %d impropers in data file " % (n_impropers) sys.exit(" Inconsistent number of impropers ") # # Intialize # - read in boolean to off # read_Masses = 0 read_Pair = 0 read_Bond_coeff = 0 read_Angle_coeff = 0 read_Dihedral_coeff = 0 read_Improper_coeff = 0 read_Atoms = 0 read_Bonds = 0 read_Angles = 0 read_Dihedrals = 0 read_Impropers = 0 # - lists as indecise can be out of order in data file ATYPE_REF = n_atypes * [""] ATYPE_MASS = np.zeros(n_atypes) ATYPE_EP = np.zeros(n_atypes) ATYPE_SIG = np.zeros(n_atypes) BTYPE_REF = n_btypes * [2 * [""]] BONDTYPE_R0 = np.zeros(n_btypes) BONDTYPE_K = np.zeros(n_btypes) ANGTYPE_REF = n_angtypes * [3 * [""]] ANGLETYPE_R0 = np.zeros(n_angtypes) ANGLETYPE_K = np.zeros(n_angtypes) DTYPE_REF = n_dtypes * [4 * [""]] DIHTYPE_C = np.zeros((n_dtypes, 4)) DIHTYPE_F = np.zeros(n_dtypes) DIHTYPE_K = np.zeros(n_dtypes) DIHTYPE_PN = np.zeros(n_dtypes) DIHTYPE_PHASE = np.zeros(n_dtypes) IMPTYPE_REF = n_imptypes * [4 * [""]] IMPTYPE_F = np.zeros(n_imptypes) IMPTYPE_E0 = np.zeros(n_imptypes) IMPTYPE_K = np.zeros(n_imptypes) MOLNUMB = n_atoms * [0] ATYPE_IND = n_atoms * [0] CHARGES = np.zeros(n_atoms) R = n_atoms * [np.zeros(3)] ATYPE = n_atoms * [""] BONDS = n_bonds * [[0, 0]] BTYPE_IND = n_bonds * [0] ANGLES = n_angles * [[0, 0, 0]] ANGTYPE_IND = n_angles * [0] DIH = n_dihedrals * [[0, 0, 0, 0]] DTYPE_IND = n_dihedrals * [0] # # Check if values exist and need to be updated or don't and need to be created # ljtyp_update = False ljtyp_cnt = 0 if (len(parmC.ljtypC) > 0): print " LJ types will be updated " ljtyp_update = True btyp_update = False btyp_cnt = 0 if (len(parmC.btypC) > 0): print " Bond types will be updated " btyp_update = True atyp_update = False atyp_cnt = 0 if (len(parmC.atypC) > 0): print " Angle types will be updated " atyp_update = True dtyp_update = False dtyp_cnt = 0 if (len(parmC.dtypC) > 0): print " Dihedral types will be updated " dtyp_update = True imptyp_update = False imptyp_cnt = 0 if (len(parmC.imptypC) > 0): print " Improper dihedrals types will be updated " imptyp_update = True # # Read in data parameters # for line in lines: col = line.split() if (read_Masses and len(col) >= 2): cnt_Masses += 1 ind = int(col[0]) - 1 ATYPE_MASS[ind] = float(col[1]) if (len(col) >= 4): ATYPE_REF[ind] = col[3] ptype1 = col[3] else: ATYPE_REF[ind] = "??" ptype1 = "??" mass_i = float(col[1]) if (ljtyp_update): ljtyp_cnt = ind + 1 if (ljtyp_cnt > len(parmC.ljtypC)): print "Mass index %d larger then length of previously read ljtypC %d" % ( ind, len(parmC.ljtypC)) ljtyp_i = parmC.ljtypC[ljtyp_cnt] ljtyp_i.setmass(mass_i) else: ljtyp_i = ljtype(ptype1) ljtyp_i.setmass(mass_i) parmC.ljtypC.put(ljtyp_i) # Turn of mass read if (cnt_Masses == n_atypes): read_Masses = 0 if (read_Pair and len(col) >= 3): cnt_Pair += 1 ind = int(col[0]) - 1 ATYPE_EP[ind] = float(col[1]) ATYPE_SIG[ind] = float(col[2]) epsilon = float(col[1]) sigma = float(col[2]) ljtyp_ind = int(col[0]) ljtyp_i = parmC.ljtypC[ljtyp_ind] ljtyp_i.setparam(epsilon, sigma) # Turn pair parameter read off if (cnt_Pair >= n_atypes): read_Pair = 0 if (read_Bond_coeff and len(col) >= 3): cnt_Bond_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) b_ind = int(col[0]) - 1 if (b_ind > n_btypes): error_line = " Error in data file index of bond parameter exceeds number of bond parameters specified with bond types " sys.exit(error_line) BTYPE_REF[b_ind][0] = "??" BTYPE_REF[b_ind][1] = "??" BONDTYPE_K[b_ind] = float(col[1]) BONDTYPE_R0[b_ind] = float(col[2]) ptype1 = "??" ptype2 = "??" lmpindx = int(col[0]) kb = float(col[1]) r0 = float(col[2]) btype = "harmonic" g_type = 1 if (btyp_update): btyp_cnt = b_ind + 1 btyp_i = parmC.btypC[btyp_cnt] btyp_i.setharmonic(r0, kb) btyp_i.set_g_indx(g_type) btyp_i.set_lmpindx(lmpindx) else: btyp_i = bondtype(ptype1, ptype2, btype) btyp_i.setharmonic(r0, kb) btyp_i.set_g_indx(g_type) btyp_i.set_lmpindx(lmpindx) parmC.btypC.put(btyp_i) if (cnt_Bond_coeff >= n_btypes): read_Bond_coeff = 0 if (read_Angle_coeff and len(col) >= 3): cnt_Angle_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) a_ind = int(col[0]) - 1 if (a_ind > n_angtypes): print sys.exit( " Error in data file index of angle parameter exceeds number of angle parameters specified with angle types " ) ANGTYPE_REF[a_ind][0] = "??" ANGTYPE_REF[a_ind][1] = "??" ANGTYPE_REF[a_ind][2] = "??" ANGLETYPE_K[a_ind] = float(col[1]) ANGLETYPE_R0[a_ind] = float(col[2]) ptype1 = "??" ptype2 = "??" ptype3 = "??" lmpindx = int(col[0]) theta0 = float(col[2]) # degrees kb = float(col[1]) atype = "harmonic" gfunc_type = 1 if (atyp_update): atyp_cnt = a_ind + 1 atyp_i = parmC.atypC[atyp_cnt] atyp_i.set_g_indx(gfunc_type) atyp_i.set_lmpindx(lmpindx) atyp_i.setharmonic(theta0, kb) else: atyp_i = angletype(ptype1, ptype2, ptype3, atype) atyp_i.set_g_indx(gfunc_type) atyp_i.set_lmpindx(lmpindx) atyp_i.setharmonic(theta0, kb) parmC.atypC.put(atyp_i) if (cnt_Angle_coeff >= n_angtypes): read_Angle_coeff = 0 if (read_Dihedral_coeff and len(col) >= 3): cnt_Dihedral_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) d_ind = int(col[0]) - 1 if (debug): print " reading dih type ", d_ind, " cnt ", cnt_Dihedral_coeff, " of ", n_dtypes if (d_ind > n_dtypes): error_line = " Error in data file index of dihedral parameter %d exceeds number of dihedral parameters %d " % ( d_ind, n_dtypes) error_line += " specified with dihedral types " print sys.exit(error_line) DTYPE_REF[d_ind][0] = "??" DTYPE_REF[d_ind][1] = "??" DTYPE_REF[d_ind][2] = "??" DTYPE_REF[d_ind][3] = "??" # Assume OPLS dihedral type DIHTYPE_F[d_ind] = 3 DIHTYPE_C[d_ind][0] = float(col[1]) DIHTYPE_C[d_ind][1] = float(col[2]) DIHTYPE_C[d_ind][2] = float(col[3]) DIHTYPE_C[d_ind][3] = float(col[4]) ptype1 = "??" ptype2 = "??" ptype3 = "??" ptype4 = "??" # Set parameters according to type gfunc_type = 3 dtype = "opls" lmpindx = int(col[0]) k1 = float(col[1]) k2 = float(col[2]) k3 = float(col[3]) k4 = float(col[4]) if (dtyp_update): dtyp_cnt = d_ind + 1 dtyp_i = parmC.dtypC[dtyp_cnt] dtyp_i.set_g_indx(gfunc_type) dtyp_i.set_lmpindx(lmpindx) dtyp_i.setopls(k1, k2, k3, k4) else: dtyp_i = dihtype(ptype1, ptype2, ptype3, ptype4, dtype) dtyp_i.set_g_indx(gfunc_type) dtyp_i.set_lmpindx(lmpindx) dtyp_i.setopls(k1, k2, k3, k4) parmC.dtypC.put(dtyp_i) if (cnt_Dihedral_coeff >= n_dtypes): read_Dihedral_coeff = 0 if (read_Improper_coeff and len(col) >= 3): cnt_Improper_coeff += 1 #AT_i = int(col[0]) #AT_j = int(col[1]) imp_ind = int(col[0]) - 1 if (debug): print " reading imp dih type ", imp_ind, " cnt ", cnt_Improper_coeff, " of ", n_imptypes if (imp_ind > n_imptypes): error_line = " Error in data file index of improper parameter %d exceeds number of improper parameters %d " % ( imp_ind, n_imptypes) error_line += " specified with dihedral types " print sys.exit(error_line) IMPTYPE_REF[imp_ind][0] = "??" IMPTYPE_REF[imp_ind][1] = "??" IMPTYPE_REF[imp_ind][2] = "??" IMPTYPE_REF[imp_ind][3] = "??" # Assume OPLS dihedral type IMPTYPE_F[imp_ind] = 2 KE = float(col[1]) Eo = float(col[2]) IMPTYPE_E0[imp_ind] = Eo IMPTYPE_K[imp_ind] = KE ptype1 = "??" ptype2 = "??" ptype3 = "??" ptype4 = "??" # Set parameters according to type g_indx = 2 dtype = "improper" lmpindx = int(col[0]) if (imptyp_update): imptyp_cnt = imp_ind + 1 imptyp_i = parmC.imptypC[imptyp_cnt] imptyp_i.set_g_indx(g_indx) imptyp_i.setimp(Eo, KE) imptyp_i.set_lmpindx(lmpindx) else: imptyp_i = imptype(ptype1, ptype2, ptype3, ptype4, dtype) imptyp_i.set_g_indx(g_indx) imptyp_i.setimp(Eo, KE) imptyp_i.set_lmpindx(lmpindx) parmC.imptypC.put(imptyp_i) if (cnt_Improper_coeff >= n_imptypes): read_Improper_coeff = 0 if (read_Atoms and len(col) >= 7): cnt_Atoms += 1 ind = int(col[0]) - 1 if (ind > n_atoms): print sys.exit( " Error in data file index of atoms exceeds number of atoms specified with atoms " ) chain_i = int(col[1]) lmptype_i = int(col[2]) #- 1 indx = int(col[2]) - 1 q_i = float(col[3]) m_i = ATYPE_MASS[indx] fftype_i = ATYPE_REF[indx] el = pt.getelementWithMass(m_i) if (el.symbol == "VS"): el.symbol = ATYPE_l[atom_indx].strip() fftype_i = "VS" m_i = 0.0 # HACK !! if (ATYPE_MASS[indx] == 9.0): el.symbol = "LP" fftype_i = "LP" m_i = 0.0 r_i = [float(col[4]), float(col[5]), float(col[6])] type_i = str(lmptype_i) #tagsD = {"chain":chain_i,"symbol":el.symbol,"number":el.number,"mass":el.mass,"cov_radii":el.cov_radii,"vdw_radii":el.vdw_radii} #if( pt_overwrite ): pt_i = strucC.ptclC[ind + 1] pt_i.position = r_i pt_i.charge = q_i pt_i.mass = m_i add_dict = pt_i.tagsDict # Set properties read in data file if (set_chain_numbers): add_dict["chain"] = chain_i add_dict["symbol"] = el.symbol add_dict["number"] = el.number add_dict["mass"] = el.mass add_dict["cov_radii"] = el.cov_radii add_dict["vdw_radii"] = el.vdw_radii add_dict["lmptype"] = lmptype_i add_dict["fftype"] = fftype_i # add_dict["ffmass"] = ATYPE_MASS[indx] pt_i.setTagsDict(add_dict) if (cnt_Atoms >= n_atoms): read_Atoms = 0 if (read_Bonds and len(col) >= 4): cnt_Bonds += 1 ind = int(col[0]) - 1 if (ind > n_bonds): print sys.exit( " Error in data file index of bonds exceeds number of bonds specified with bonds " ) BTYPE_IND[ind] = int(col[1]) - 1 BONDS[ind] = [int(col[2]) - 1, int(col[3]) - 1] i_o = int(col[2]) j_o = int(col[3]) if (bonds_overwrite): bondObj = strucC.bondC[cnt_Bonds] bondObj.pgid1 = i_o bondObj.pgid2 = j_o bondObj.set_lmpindx(int(col[1])) else: bondObj = Bond(i_o, j_o) bondObj.set_lmpindx(int(col[1])) strucC.bondC.put(bondObj) if (cnt_Bonds >= n_bonds): read_Bonds = 0 if (read_Angles and len(col) >= 5): cnt_Angles += 1 ind = int(col[0]) - 1 ANGTYPE_IND[ind] = int(col[1]) - 1 ANGLES[ind] = [int(col[2]) - 1, int(col[3]) - 1, int(col[4]) - 1] k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) if (cnt_Angles >= n_angles): read_Angles = 0 if (angles_overwrite): angleObj = strucC.angleC[cnt_Angles] angleObj.pgid1 = k_o angleObj.pgid2 = i_o angleObj.pgid3 = j_o angleObj.set_lmpindx(int(col[1])) else: angleObj = Angle(k_o, i_o, j_o) angleObj.set_lmpindx(int(col[1])) strucC.angleC.put(angleObj) if (read_Dihedrals and len(col) >= 6): cnt_Dihedrals += 1 ind = int(col[0]) - 1 DTYPE_IND[ind] = int(col[1]) - 1 DIH[ind] = [ int(col[2]) - 1, int(col[3]) - 1, int(col[4]) - 1, int(col[5]) - 1 ] k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) l_o = int(col[5]) if (dih_overwrite): dObj = strucC.dihC[cnt_Dihedrals] dObj.pgid1 = k_o dObj.pgid2 = i_o dObj.pgid3 = j_o dObj.pgid4 = l_o dObj.set_lmpindx(int(col[1])) else: dObj = Dihedral(k_o, i_o, j_o, l_o) dObj.set_lmpindx(int(col[1])) strucC.dihC.put(dObj) if (cnt_Dihedrals >= n_dihedrals): read_Dihedrals = 0 if (read_Impropers and len(col) >= 2): cnt_Impropers += 1 ind = int(col[0]) - 1 k_o = int(col[2]) i_o = int(col[3]) j_o = int(col[4]) l_o = int(col[5]) if (imp_overwrite): impObj = strucC.impC[cnt_Impropers] impObj.pgid1 = k_o impObj.pgid2 = i_o impObj.pgid3 = j_o impObj.pgid4 = l_o impObj.set_lmpindx(int(col[1])) impObj.set_type("improper") else: impObj = Improper(k_o, i_o, j_o, l_o) impObj.set_lmpindx(int(col[1])) impObj.set_type("improper") strucC.impC.put(impObj) if (cnt_Impropers >= n_impropers): read_Impropers = 0 if (len(col) >= 1): if (col[0] == "Masses"): read_Masses = 1 cnt_Masses = 0 if (col[0] == "Atoms"): read_Atoms = 1 cnt_Atoms = 0 if (col[0] == "Bonds"): read_Bonds = 1 cnt_Bonds = 0 if (col[0] == "Angles"): read_Angles = 1 cnt_Angles = 0 if (col[0] == "Dihedrals"): read_Dihedrals = 1 cnt_Dihedrals = 0 if (col[0] == "Impropers"): read_Impropers = 1 cnt_Impropers = 0 if (len(col) >= 2): if (col[0] == "Pair" and col[1] == "Coeffs"): read_Pair = 1 cnt_Pair = 0 if (col[0] == "Bond" and col[1] == "Coeffs"): read_Bond_coeff = 1 cnt_Bond_coeff = 0 if (col[0] == "Angle" and col[1] == "Coeffs"): read_Angle_coeff = 1 cnt_Angle_coeff = 0 if (col[0] == "Dihedral" and col[1] == "Coeffs"): read_Dihedral_coeff = 1 cnt_Dihedral_coeff = 0 if (col[0] == "Improper" and col[1] == "Coeffs"): read_Improper_coeff = 1 cnt_Improper_coeff = 0 # cnt_Bonds += 1 # ind = int( col[0]) - 1 # BTYPE_IND[ind] = int(col[1] ) - 1 # BONDS[ind][0] = int(col[2]) # if( cnt_Bonds >= n_atoms ): # read_Bonds = 0 # # if (ljtyp_update): if (ljtyp_cnt != len(parmC.ljtypC)): print " Number of LJ types read in %d does not match previously read %d " % ( ljtyp_cnt, len(parmC.ljtypC)) if (debug): for ind in range(len(ATYPE_MASS)): print ind + 1, ATYPE_MASS[ind] for ind in range(len(ATYPE_EP)): print ind + 1, ATYPE_EP[ind], ATYPE_SIG[ind] for ind in range(n_btypes): print ind + 1, BONDTYPE_R0[ind], BONDTYPE_K[ind] for ind in range(n_angtypes): print ind + 1, ANGLETYPE_R0[ind], ANGLETYPE_K[ind] for ind in range(n_dtypes): print ind + 1, DIHTYPE_C[ind] debug = 0 if (debug): for ind in range(len(BONDS)): print ind + 1, BONDS[ind] if (debug): sys.exit("debug 1 ") # # return (strucC, parmC)
def main(): """ This test shows structureContainer functionality with dihedrals included """ print "************************************************************************************" print " This test shows structureContainer functionality with dihedrals included" print "************************************************************************************ \n" p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([4.4, 4.4, 4.4], "Si", 1.0, 2.34) # p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 1 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 2 p7 = Particle([7.7, 7.7, 7.7], "C", 1.0, 2.34) # 3 p8 = Particle([8.8, 8.8, 8.8], "C", 1.0, 2.34) # 4 b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") b3 = Bond(3, 4, 3.33, "hooke") # b4 = Bond(1, 2, 4.44, "hooke") b5 = Bond(2, 3, 5.55, "hooke") b6 = Bond(3, 4, 6.66, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") d1 = Dihedral(1, 2, 3, 4, 1.11, "stiff") # d2 = Dihedral(1, 2, 3, 4, 2.22, "stiff") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) # atoms2.put(p5) atoms2.put(p6) atoms2.put(p7) atoms2.put(p8) bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds1.put(b3) # bonds2.put(b4) bonds2.put(b5) bonds2.put(b6) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) dih1 = DihedralContainer() dih2 = DihedralContainer() dih1.put(d1) dih2.put(d2) polymer1 = StructureContainer(atoms1, bonds1, angles1, dih1) polymer2 = StructureContainer(atoms2, bonds2, angles2, dih2) del p1, p2, p3, p4, p5, p6, p7, p8 del b1, b2, b3, b4, b5, b6, a1, a2, d1, d2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2, dih1, dih2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer1 += polymer2) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2
def main(): """ This test shows structureContainer functionality with angles included """ print "************************************************************************************" print " This test shows structureContainer functionality with angles included" print "************************************************************************************ \n" p1 = Particle( [1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle( [2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle( [3.3, 3.3, 3.3], "Si", 1.0, 2.34) # p4 = Particle( [4.4, 4.4, 4.4], "C", 1.0, 2.34) # 1 p5 = Particle( [5.5, 5.5, 5.5], "C", 1.0, 2.34) # 2 p6 = Particle( [6.6, 6.6, 6.6], "C", 1.0, 2.34) # 3 b1 = Bond( 1, 2, 1.11, "hooke") b2 = Bond( 2, 3, 2.22, "hooke") # b3 = Bond( 1, 2, 3.33, "hooke") b4 = Bond( 2, 3, 4.44, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) # atoms2.put(p4) atoms2.put(p5) atoms2.put(p6) bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds2.put(b3) bonds2.put(b4) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) polymer1 = StructureContainer(atoms1, bonds1, angles1) polymer2 = StructureContainer(atoms2, bonds2, angles2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer1 += polymer2) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2
def main(): """ This test shows how to set up Structure container with Particle/Bond-Containers Shows how ID changed in Structure propagate to values set in BondContainer and and an AngleContainer for its held particle ID values Illustrates how a substructure method could return subgroup """ print "************************************************************************************" print " This test shows how to set up Structure container with Particle/Bond-Containers \n" print " Shows how ID changed in Structure propagate to values set in BondContainer and " print " and an AngleContainer for its held particle ID values \n" print " Illustrates how a substructure method could return subgroup" print "************************************************************************************ \n" p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23) p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34) p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34) p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34) p5 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23) b1 = Bond(5, 2, 1.233, "hooke") # This setup mimics earlier state of test b2 = Bond(2, 3, 0.500, "hooke") # Still matches with diagram b3 = Bond(3, 4, 2.301, "hooke") b4 = Bond(5, 3, 0.828, "hooke") a1 = Angle(1, 2, 3, 1.111, "harmonic") a2 = Angle(2, 3, 4, 2.222, "harmonic") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) atoms1.put(p5) del atoms1[1] # This is to mimic state of container for an older test bonds = BondContainer() bonds.put(b1) bonds.put(b2) bonds.put(b3) bonds.put(b4) angles = AngleContainer() angles.put(a1) angles.put(a2) del p1, p2, p3, p4, b1, b2, b3, b4, a1, a2 polymer1 = StructureContainer(atoms1, bonds, angles) del atoms1, bonds, angles print "********************************************************** \n" print polymer1 print diagramAfter print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubStructure([5,2])" print " currently ID's are reassigned in substructure \n" subpolymer = polymer1.getSubStructure([5, 2]) print subpolymer print diagramAfter print "********************************************************** \n" print "********************************************************** \n" print "polymer1 Struture after returning sub-structure" print polymer1 print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubStructure([2,3,4])" print " currently ID's are reassigned in substructure \n" subpolymer = polymer1.getSubStructure([2, 3, 4]) print subpolymer print diagramAfter print "********************************************************** \n"