def dont_test_compare_ubs(self):
     """ISAWev does not take into account the goniometer angles when outputting the
     UB matrix file. ISAW does. This compares the U and B matrices obtained from both.
     """
     #0, np.pi/4, 0
     c = Crystal("oxalic acid")
     c.read_ISAW_ubmatrix_file("data/TOPAZ_1204.mat", angles=[0, np.pi/4, 0])
     c2 = Crystal("oxalic acid from EV")
     c2.read_ISAW_ubmatrix_file("data/TOPAZ_1204_ev.mat", angles=[0, 0, 0])
     assert np.allclose(c.reciprocal_lattice, c2.reciprocal_lattice, atol=0.05), "B matrices match, roughly. %s vs %s" % (c.reciprocal_lattice, c2.reciprocal_lattice)
     assert np.allclose(c.u_matrix, c2.u_matrix, atol=0.02), "U matrices match, roughly. %s vs %s" % (c.u_matrix, c2.u_matrix)
     print "\n\n\n"
     print c.u_matrix
     print c2.u_matrix
Esempio n. 2
0
    def test_substructure_preservation(self):
        """ Test that initializing a crystal with substructures preserves the substructures """
        atoms = [Atom("Ag", [0, 0, 0]), Atom("Ag", [1, 1, 1])]
        substructures = [AtomicStructure(atoms=[Atom("U", [0, 0, 0])])]
        c = Crystal(unitcell=atoms + substructures, lattice_vectors=np.eye(3))

        self.assertEqual(len(c), 3)
        self.assertIn(substructures[0], c.substructures)
Esempio n. 3
0
def test_substructure_preservation():
    """Test that initializing a crystal with substructures preserves the substructures"""
    atoms = [Atom("Ag", [0, 0, 0]), Atom("Ag", [1, 1, 1])]
    substructures = [AtomicStructure(atoms=[Atom("U", [0, 0, 0])])]
    c = Crystal(unitcell=atoms + substructures, lattice_vectors=np.eye(3))

    assert len(c) == 3
    assert substructures[0] in c.substructures
   def test_reciprocal_matrix2(self):
       c = Crystal("oxalic acid")
       c.lattice_angles_deg = np.fromstring("90.0 103.2  90.0", sep=' ')
       c.lattice_lengths = np.fromstring("6.094  3.601 11.915", sep=' ')
       c.calculate_reciprocal()
       isaw_rec = np.fromstring("""   1.031045    0.000000    0.000000
 -0.000000    1.744845    0.000000
  0.241829   -0.000000    0.54164""", sep=' ').reshape(3,3)
       assert np.allclose(isaw_rec, c.reciprocal_lattice), "Reciprocal lattice of %s matches ISAW lattice." % c.name
   def test_reciprocal_matrix1(self):
       c = Crystal("quartz")
       c.lattice_angles_deg = np.fromstring("90.0  90.0 120.0", sep=' ')
       c.lattice_lengths = np.fromstring("4.913  4.913  5.400", sep=' ')
       c.calculate_reciprocal()
       isaw_rec = np.fromstring("""   1.278890    0.000000    0.000000
  0.738367    1.476735   -0.000000
 -0.000000   -0.000000    1.163553""", sep=' ').reshape(3,3)
       assert np.allclose(isaw_rec, c.reciprocal_lattice), "Reciprocal lattice of %s matches ISAW lattice." % c.name
   def test_reciprocal_matrix4(self):
       c = Crystal("Natrolite(conventional orthorhombic cell)")
       c.lattice_angles_deg = np.fromstring("90.0  90.0  90.0", sep=' ')
       c.lattice_lengths = np.fromstring("18.328 18.585  6.597", sep=' ')
       c.calculate_reciprocal()
       isaw_rec = np.fromstring("""   0.342819    0.000000    0.000000
 -0.000000    0.338078    0.000000
 -0.000000   -0.000000    0.952431 """, sep=' ').reshape(3,3)
       #print c.reciprocal_lattice, "\n\n\n"
       assert np.allclose(isaw_rec, c.reciprocal_lattice, atol=1e-5), "Reciprocal lattice of %s matches ISAW lattice." % c.name
   def test_reciprocal_matrix3(self):
       c = Crystal("Natrolite(reduced cell)")
       c.lattice_angles_deg = np.fromstring("83.5  70.5  70.2", sep=' ')
       c.lattice_lengths = np.fromstring("6.601  9.739  9.893", sep=' ')
       c.calculate_reciprocal()
       isaw_rec = np.fromstring("""   0.951854   -0.000000    0.000000
 -0.342876    0.685738    0.000000
 -0.336898    0.000033    0.673719 """, sep=' ').reshape(3,3)
       #print c.reciprocal_lattice, "\n\n\n"
       assert np.allclose(isaw_rec, c.reciprocal_lattice, atol=1e-3), "Reciprocal lattice of %s matches ISAW lattice." % c.name
Esempio n. 8
0
def update():
    global aPressed, gameMode, bPressed, cPressed, shuttleTimer, enemyTimer, bossTimer
    global gameState, scoreCtr, score, highscore, shakeX, bulletCount, health, rockSizes, crystalSizes, enemyShipSizes, bossShipSizes
    global upPressed, downPressed, leftPressed, rightPressed, explosionList, explosionFrames
    global shuttle, enemyList, bulletList, dropList, bombs, bossList, spaceman, pauseGame
    destroyScreen = False
    shipHitShuttle = False
    
    # Get screen shake amount (use on all x positions of objects!)
    ######################################
    shakeX = shake.update()
    
    if gameState != STATE_PAUSE:
        # Update stars
        ######################################
        for star in starList:
            star.update()
            
        # Update rocks
        ######################################
        for boulders in rockList:
            boulders.update(rockSizes)
    
    ######################################
    # Game state
    ######################################
    if gameState == STATE_GAME:

        # Update the score for player survival
        ######################################
        scoreCtr += 1
        if scoreCtr % 10 == 0:
            score += 1
        
        if cPressed:
            gameState = STATE_PAUSE
            cPressed = False
            
        # Bomb button
        ######################################
        if bPressed:
            bPressed = False
            if bombs > 0:
                bombs -= 1
                destroyScreen = True
        
        # Move player
        ######################################
        shipXMove = 0
        shipYMove = 0
        if upPressed:
            shipYMove = -2
        if downPressed:
            shipYMove = 2
        if leftPressed:
            shipXMove = -2
        if rightPressed:
            shipXMove = 2

        player.movePlayer(shipXMove, shipYMove)
        
        # Update player ship flames
        ######################################
        for flame in flameList:
            flame.update(player.getPlayerPos()[0], player.getPlayerPos()[1] + 20)
            
        # Update drops
        ######################################
        if len(dropList) > 0:
            tmpCtr = 0
            for dropItem in dropList:
                
                # Delete drop if out of screen
                if dropItem.update():
                    del dropList[tmpCtr]
                    break
            
                # Check if player is over drop
                if detectHit(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, dropItem.returnPos()[0] - 2, dropItem.returnPos()[1] - 2, 14):
                    # Health / green
                    if dropItem.getType() == 0:
                        audio.playSfx(sounds.health)
                        health = 10
                    
                    # Extra bullet / orange
                    elif dropItem.getType() == 1:
                        audio.playSfx(sounds.extraBullet)
                        if bulletCount == 8:
                            bulletCount += 1
                        elif bulletCount < 8:
                            bulletCount += 2
                        
                    # Explosion/bonus / blue
                    else:
                        audio.playSfx(sounds.bonus)
                        score += 100
                        if bombs < 10:
                            bombs += 1
                        
                    del dropList[tmpCtr]
                    break
                    
                tmpCtr += 1
                
            # Delete drop object
            ######################################
            if tmpCtr > 0:
                gc.collect()
        
        # Check crystal collisions
        ######################################
        if len(crystalList) > 0:
            crystalCtr = 0
            delCrystal = False
            for crystal in crystalList:
                crystal.update()
                # Has player hit crystal?
                if detectHit(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, crystal.returnPos()[0], crystal.returnPos()[1], crystal.getSize()):
                    del crystalList[crystalCtr]
                    delCrystal = True
                    score += 50
                    audio.playSfx(sounds.bonus)
                
                if crystal.returnPos()[1] >= 100:
                    del crystalList[crystalCtr]
                    delCrystal = True
                    
                # Destroy if player bombed
                if destroyScreen:
                    explosionList.append(Explosion(crystal.returnPos()[0], crystal.returnPos()[1], len(explosionFrames)))
                    del crystalList[crystalCtr]
                    delCrystal = True
                    
                crystalCtr += 1
                
            if delCrystal:
                gc.collect()
            
        # Check to see if new crystals need to be spawned
        ######################################
        if random.getrandbits(7) > 126:
            tmpX = random.getrandbits(7)
            spdX = random.getrandbits(1)
            spdY = random.getrandbits(2)
            if spdY == 0:
                spdY = 1
            crystalId = random.getrandbits(3)
            # Only 6 crystals to choose from
            if crystalId > 5:
                crystalId = 0
            crystalList.append(Crystal(tmpX, -20, spdX, spdY, crystalId, crystalSizes[crystalId]))
        
        # Check rock collisions
        ######################################
        for boulders in rockList:
            if detectHit(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, boulders.returnPos()[0], boulders.returnPos()[1], boulders.getSize()) and not shake.isShaking():
                shake.setShake()
                explosionList.append(Explosion(boulders.returnPos()[0], boulders.returnPos()[1], len(explosionFrames)))
                boulders.resetYPos(rockSizes)    # Reset as if it has exploded
                health -= 1
                audio.playSfx(sounds.explosion01)
                if health <= 0:
                    gameState = STATE_GAMEOVER
                    audio.playSfx(sounds.gameOver)
                    
            # Destroy if player bombed
            if destroyScreen:
                shake.setShake()
                explosionList.append(Explosion(boulders.returnPos()[0], boulders.returnPos()[1], len(explosionFrames)))
                boulders.resetYPos(rockSizes)

        # Update explosion
        ######################################
        if len(explosionList) > 0:
            tmpId = 0
            tmpCtr = 0
            for explody in explosionList:
                tmpId += 1
                if explody.getFrame() >= len(explosionFrames):
                    tmpCtr = tmpId
                    break
                
                explody.update()
        
            # Delete explosion object
            ######################################
            if tmpCtr > 0:
                del explosionList[tmpCtr - 1]
                gc.collect()
        
        # Create random shuttle
        ######################################
        if scoreCtr % shuttleTimer == 0:
            if random.getrandbits(1) == 1:
                shuttle[2] = True
        
        # Update shuttle
        ######################################
        if shuttle[2]:
            shuttle[1] += 1
            if destroyScreen:
                explosionList.append(Explosion(shuttle[0], shuttle[1], len(explosionFrames)))
                audio.playSfx(sounds.explosion01)
                # Spawn drop
                dropList.append(Drop(shuttle[0], shuttle[1]))
                
            # Check if player ship hit shuttle
            if detectHit(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, shuttle[0], shuttle[1], 10):
                explosionList.append(Explosion(shuttle[0], shuttle[1], len(explosionFrames)))
                audio.playSfx(sounds.explosion01)
                # Spawn drop
                dropList.append(Drop(shuttle[0], shuttle[1]))
                shipHitShuttle = True
                health -= 1
                if health <= 0:
                    gameState = STATE_GAMEOVER
                    audio.playSfx(sounds.gameOver)
            
            if shuttle[1] > 90 or destroyScreen or shipHitShuttle:
                shuttle[2] = False                  # Hide it
                shuttle[1] = -30                    # Set y pos to top
                shuttle[0] = random.getrandbits(7)  # Random x pos
            
        # Update spaceman
        ######################################
        if spaceman[2]:
            spcX = 0
            spcY = 0
            
            # Check if player caught him
            if detectHit(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, spaceman[0], spaceman[1], 12):
                score += 50
                audio.playSfx(sounds.dropItem)
                # Reset him
                spaceman = [0, 0, False]
            
            # Move him down
            if spaceman[0] > -12 and spaceman[0] < 122:
                if spaceman[1] > -12 and spaceman[1] < 100:
                    spcX = random.getrandbits(3)
                    spcY = random.getrandbits(3)
                    if spcX < 3:
                        spcX = -1
                    else:
                        spcX = 1
                    if spcY < 3:
                        spcY = -1
                    else:
                        spcY = 1

            spaceman[0] += spcX
            spaceman[1] += spcY
            
            # disappear him if needed
            if spaceman[0] < 0 or spaceman[0] > 110:
                if spaceman[1] < 0 or spaceman[1] > 88:
                    spaceman = [0, 0, False]
            
        # Then update enemies
        ######################################
        if len(enemyList) > 0:
            tmpId = 0
            tmpCtr = 0
            for en in enemyList:
                tmpId += 1
                
                # Check if enemy can shoot
                if en.update():
                    
                    # Horizontal enemy
                    if en.getSize() == 0:
                        if en.returnPos()[0] > 0:
                            bulletList.append(Bullet(en.returnPos()[0] + 4, en.returnPos()[1] + 15, 0, 2, 1))
                            audio.playSfx(sounds.enemyShot)
                    # All others
                    else:
                        if en.returnPos()[1] > 0:
                            bulletList.append(Bullet(en.returnPos()[0] + 4, en.returnPos()[1] + 15, -1, 2, 2))
                            bulletList.append(Bullet(en.returnPos()[0] + 4, en.returnPos()[1] + 15, 1, 2, 2))
                            audio.playSfx(sounds.enemyShot)
                    
                # Is enemy out of the screen yet?
                if en.outOfScreen():
                    tmpCtr = tmpId
                    break
                
                if destroyScreen:
                    explosionList.append(Explosion(en.returnPos()[0], en.returnPos()[1], len(explosionFrames)))
                    # Spawn drop
                    dropList.append(Drop(en.returnPos()[0], en.returnPos()[1]))
                    del enemyList[tmpCtr - 1]
                    
            # Delete enemy object
            ######################################
            if tmpCtr > 0:
                del enemyList[tmpCtr - 1]
                gc.collect()
            
        # Create random enemies
        ######################################
        if scoreCtr % enemyTimer == 0:
            
            if len(enemyList) > 3:
                enemyListTmp = enemyList[len(enemyList) - 1]
                enemyList = [enemyListTmp]
            else:
                enemyList.append(Enemy())
            
        # Create random bosses
        ######################################
        if len(bossList) > 0:
            tmpId = 0
            tmpCtr = 0
            for boss in bossList:
                tmpId += 1
                bossId = boss.getId()
                bossX = boss.returnPos()[0]
                bossY = boss.returnPos()[1]
                
                # Check if enemy can shoot
                if boss.update():
                    
                    # Horizontal enemy
                    if boss.getId() == 0 or boss.getId() == 2:
                        if boss.returnPos()[0] > 0:
                            bulletList.append(Bullet(bossX + (bossShipSizes[bossId] // 2), bossY + 17, 0, 2, bossId + 1))
                            audio.playSfx(sounds.enemyShot)
                    # All others
                    else:
                        if boss.returnPos()[1] > 0:
                            bulletList.append(Bullet(bossX + (bossShipSizes[bossId] // 2), bossY + 17, -1, 2, bossId + 1))
                            bulletList.append(Bullet(bossX + (bossShipSizes[bossId] // 2), bossY + 17, 1, 2, bossId + 1))
                            audio.playSfx(sounds.enemyShot)
                    
                # Is enemy out of the screen yet?
                if boss.outOfScreen():
                    tmpCtr = tmpId
                    break
                
                if destroyScreen:
                    explosionList.append(Explosion(boss.returnPos()[0], boss.returnPos()[1], len(explosionFrames)))
                    # Spawn drop
                    dropList.append(Drop(boss.returnPos()[0], boss.returnPos()[1]))
                    del bossList[tmpCtr - 1]
                    
            # Delete enemy object
            ######################################
            if tmpCtr > 0:
                del bossList[tmpCtr - 1]
                gc.collect()
        
        # Create random bosses
        ######################################
        if scoreCtr % bossTimer == 0:
            
            if len(bossList) > 1:
                bossListTmp = bossList[len(bossList) - 1]
                bossList = [bossListTmp]
            else:
                bossList.append(Boss())
        
        # Fire button
        ######################################
        if aPressed:
            aPressed = False
            if bulletCount > 0:
                bulletList.append(Bullet(player.getPlayerPos()[0] + 5, player.getPlayerPos()[1], 0, -3, 0))
                bulletCount -= 1
                audio.playSfx(sounds.playerShot)
            
        # Update bullet positions
        ######################################
        if len(bulletList) > 0:
            tmpId = 0
            tmpCtr = 0
            for bul in bulletList:
                tmpId += 1
                bullX = bul.returnPos()[0] + 3
                bullY = bul.returnPos()[1] + 2
                bullId = bul.getId()
                
                # Check bullet collisions
                ######################################
                # Check against shuttle
                if detectHit(bullX, bullY, shuttle[0], shuttle[1], 10) and bullId == 0:
                    explosionList.append(Explosion(shuttle[0], shuttle[1], len(explosionFrames)))
                    # Spawn drop
                    dropList.append(Drop(shuttle[0], shuttle[1]))
                    # Spawn spaceman
                    spaceman[0] = shuttle[0]
                    spaceman[1] = shuttle[1]
                    spaceman[2] = True
                    # Reset shuttle
                    shuttle[2] = False                  # Hide it
                    shuttle[1] = -20                    # Set y pos to top
                    shuttle[0] = random.getrandbits(7)  # Random x pos
                    tmpCtr = tmpId                      # Kill this bullet
                    audio.playSfx(sounds.explosion01)   # Explosion
                    break
                
                # Check against enemies
                ######################################
                tmpId2 = 0
                tmpCtr2 = 0
                for en in enemyList:
                    tmpId2 += 1
                    enX = en.returnPos()[0]
                    enY = en.returnPos()[1]
                    
                    if detectHit(bullX, bullY, enX, enY, enemyShipSizes[en.getSize()]) and bullId == 0:
                        explosionList.append(Explosion(enX, enY, len(explosionFrames)))
                        tmpCtr = tmpId                      # Kill this bullet
                        tmpCtr2 = tmpId2                    # Kill this enemy
                        audio.playSfx(sounds.explosion01)   # Explosion
                        # Spawn drop
                        dropList.append(Drop(enX, enY))
                        break
                
                # Delete enemy object
                ######################################
                if tmpCtr2 > 0:
                    del enemyList[tmpCtr2 - 1]
                
                # Check against bosses
                ######################################
                tmpId3 = 0
                tmpCtr3 = 0
                for boss in bossList:
                    tmpId3 += 1
                    bossId = boss.getId()
                    bossX = boss.returnPos()[0]
                    bossY = boss.returnPos()[1]
                
                    if detectHit(bullX, bullY, bossX, bossY, bossShipSizes[bossId]) and bullId == 0:
                        explosionList.append(Explosion(bossX + (bossShipSizes[bossId] // 2), bossY + 10, len(explosionFrames)))
                        tmpCtr = tmpId                      # Kill this bullet
                        # Check boss hitpoints
                        if boss.getHitPoints() > 0:
                            boss.addHitPoint(1)
                        else:
                            tmpCtr3 = tmpId3                    # Kill this boss
                            audio.playSfx(sounds.explosion01)   # Explosion
                            # Spawn drop
                            dropList.append(Drop(bossX + (bossShipSizes[bossId] // 2), bossY + 10))
                            break
                
                # Delete boss object
                ######################################
                if tmpCtr3 > 0:
                    del bossList[tmpCtr3 - 1]
                    
                # Check against rocks
                ######################################
                for boulders in rockList:
                    boulderX = boulders.returnPos()[0]
                    boulderY = boulders.returnPos()[1]
                    if detectHit(bullX, bullY, boulderX, boulderY, boulders.getSize()) and bullId == 0:
                        explosionList.append(Explosion(boulderX, boulderY, len(explosionFrames)))
                        tmpCtr = tmpId                      # Kill this bullet
                        boulders.resetYPos(rockSizes)       # Reset as if it has exploded
                        audio.playSfx(sounds.explosion01)   # Explosion
                        break
                
                # Check against player
                ######################################
                if detectHit(bullX, bullY, player.getPlayerPos()[0], player.getPlayerPos()[1], 16) and not shake.isShaking() and bullId != 0:
                    shake.setShake()
                    explosionList.append(Explosion(player.getPlayerPos()[0] + 7, player.getPlayerPos()[1] + 7, len(explosionFrames)))
                    audio.playSfx(sounds.explosion01)   # Explosion
                    health -= 1
                    if health <= 0:
                        gameState = STATE_GAMEOVER
                        audio.playSfx(sounds.gameOver)   # Explosion
                    
                
                # Check if bullet is out of screen bounds
                ######################################
                if bul.update():
                    tmpCtr = tmpId
                    break
                
            # Delete bullet object
            ######################################
            if tmpCtr > 0:
                del bulletList[tmpCtr - 1]
                gc.collect()

        # Slowly speed up object timers to make game harder over time
        ######################################
        if scoreCtr % 80 == 0:
            if enemyTimer > 100:
                enemyTimer -= 1
                
            if bossTimer > 200:
                bossTimer -=1
    
    ######################################
    # PAUSE
    ######################################
    if gameState == STATE_PAUSE:
        if cPressed:
            cPressed = False
            gameState = STATE_GAME
    
    ######################################
    # Game over state
    ######################################
    if gameState == STATE_GAMEOVER:
        # Save score if more than highscore
        if score > highscore:
            updateScore("save", score)
            highscore = score
            
        if cPressed:
            cPressed = False
            gameState = STATE_MENU
Esempio n. 9
0
# Create rocks
for i in range(6):
    tmpX = random.getrandbits(7)
    tmpY = random.getrandbits(6)
    spdX = random.getrandbits(1)
    spdY = random.getrandbits(2)
    if spdY == 0:
        spdY = 1
    rockId = random.getrandbits(3)
    # Only 5 rocks to choose from
    if rockId > 4:
        rockId = 0
    rockList.append(Object(tmpX, tmpY, spdX, spdY, rockId, rockSizes[rockId]))

# Create an initial crystal object
crystalList.append(Crystal(50, -20, 0, 1, 0, crystalSizes[0]))

#print ("free",gc.mem_free())
# Start music
audio.playMusic(gameSong)

# save/load highscore to EEPROM
def updateScore(action, val):
    if action == "save":
        data =  val.to_bytes(3,'big')
        for i in range(len(data)): myCookieData[i]=data[i]
        
        # Save myCookieData to EEPROM.
        myCookie.save()
        
    if action == "load":
Esempio n. 10
0
from crystals import Crystal,Atom,symmetry_expansion,write_xyz
# import rotating_crystal as rcc; imp.reload(rcc)

cif='225.cif'  #201(SC), 212,225,229

lattice_vectors = np.diag([2,2,2])
cCIF = Crystal.from_cif('../dat/Carbone_SC/'+cif)
# cCIF = Crystal.from_database('Fe')
syms = cCIF.symmetry_operations()
atoms = [Atom(z, c) for z,c in zip(['C','C','C'], [[0.5,0.5,0],[0,0.5,0.5],[0.5,0.,0.5]]) ]
# atoms = [Atom('C', [0.5,0.5,1])]
# atoms = [Atom('C', [1.,1.,1.])]
syms4 = [ np.hstack([np.vstack([s[0],[0,0,0]]), np.vstack([s[1][:,None],1]) ]) for s in syms]
unitcell = symmetry_expansion(atoms,syms4)
C = Crystal(unitcell, lattice_vectors)
print('international_number:', cCIF.symmetry()['international_number'])
print('international_number:', C.symmetry()['international_number'])
print(C)
# write_xyz(C,'test.xyz')