Quickscripts

From time to time, we have to throw together a "Quickscript", something cheap-and-cheerful to do a quick job. These sorts of scripts typically take an hour or two to write (if you are an experienced programmer) to work out your algorithm etc.

Here we just keep such snippets so as they can be grabbed, cut-and-paste into a file and run.

When adding to this page, PLEASE follow the format used currently- Title, Author, Date, Introduction, Usage, Code.


Vectors.f90 

by Barry Haycock, September 2012

This is just a quick snippet to calculate the vector between the two first atoms in a bas file, taking into account the periodic images, and returns the smallest such vector. This was used when I first started trying to think of ways to analyze the delafossite data. It can be run in any FIREBALL directory, reads in a command-line argument for the .bas file (so as you can choose answer.bas or input.bas), it also reads in the input.lvs.

usage: vectors.v [basfile]


! ============================================================================
! Name        : vectors.f90
! Author      : Barry Haycock
! Version     :
! Copyright   : All Rights Reserved
! Description : reads in a bas and finds the vetor from atom 1 to atom 2, 
! spits to std out a 000 000 000 and that vector so as it can be easily graphed
! in Gnuplot.
!
! ============================================================================

program DelaAnalyser
    implicit none
    real, allocatable :: RMSes(:)
    integer numberOfTimesteps, DOSthisTimestep, numberOfAtoms

    integer i, j, testInt               !counters

    integer, allocatable :: speciesNumber(:)
    real, allocatable :: X(:), Y(:), Z(:)
    character (len = 100) :: basFileName
    real distance
    character (len = 3) nullword
    real, dimension(3) :: atom1,atom2, atomcheck, atom1check
    real, dimension(3) :: atomVec,atomZero
    real, dimension (3) :: LVS1, LVS2, LVS3


    integer optStep
    real Etot
    real cellDist, checkDist, lowDist

    integer ix, iy, iz, ix1, iy1, iz1






    call getarg(1, basFilename)
! Now the Hard Part- open answer.bas and go to that timestep.
    open (unit = 102, file = basfilename, status = "OLD")
    read (102, *) numberOfAtoms
      

    read (102, *) nullword, atom1(1), atom1(2), atom1(3)
    read (102, *) nullword, atom2(1), atom2(2), atom2(3)

    close (102)
!write(*,*) numberofAtoms
!write(*,*) nullword, atom1(1), atom1(2), atom1(3)
!write(*, *) nullword, atom2(1), atom2(2), atom2(3)

! Distance between atoms in cell:
   cellDist = distance (atom1, atom2)

   ! Find shortest distance via supercell.
   lowDist = 999
   lowDist = cellDist

! Read in LVS
   open (unit = 103, file = 'input.lvs', status = "OLD")
      read (103, *) LVS1(1), LVS1(2), LVS1(3)
      read (103, *) LVS2(1), LVS2(2), LVS2(3)
      read (103, *) LVS3(1), LVS3(2), LVS3(3)

!write(*,*) LVS1
!write(*,*) LVS2
!write(*,*) LVS3

    close (103)
    lowDist = 999.9
    lowDist = (distance (atom1, atom2))
!write(*,*) lowDist
   do ix = -1, 1
        do iy = -1, 1
           do iz = -1, 1
                do ix1 = -1, 1
                 do iy1 = -1, 1
                  do iz1 = -1, 1

              !if (ix .eq. 0 .and. iy .eq. 0 .and. iz .eq. 0) cycle
              atomCheck = atom2 + real(ix)*LVS1 + real(iy)*LVS2 + real(iz)*LVS3
              atom1Check = atom1 + real(ix1)*LVS1 + real(iy1)*LVS2 + real(iz1)*LVS3
              checkDist = distance (atom1check, atomChecK)
              if (checkDist .lt. lowDist) atomVec = atomCheck
              if (checkDist .lt. lowDist) atomZero = atom1Check
        end do
      end do
    end do
           end do
      end do
    end do

        write(*,*) "0.0000     0.00000     0.00000"
        write(*,*) atomZero(1) - atomVec(1), atomZero(2) - atomVec(2), & 
                & atomZero(3) - atomVec(3)

!        write(*,*) distance( atomZero, atomVec)
end program

        function distance (a, b)
        implicit none

        real distance

! Argument Declaration and Description
! ===========================================================================
! Input
        real, intent(in), dimension (3) :: a     !< Vector a
        real, intent(in), dimension (3) :: b     !< Vector b

! Local Parameters and Data Declaration
! ===========================================================================
! None

! Local Variable Declaration and Description
! ===========================================================================
! None

! Procedure
! ===========================================================================
        distance = sqrt ((b(1) - a(1))**2 + (b(2) - a(2))**2                &
     &                                     + (b(3) - a(3))**2)

! Format Statements
! ===========================================================================
! None

        return
        end function distance


Primbas to generate a properly-labelled set for submission (Use with Titan) 

by Barry Haycock, June 6th 2013

This is just a quick snippet to generate a bunch of directories with 4-digit integer directory names for (e.g.) Titan. The printf statement does all the work.


for a in `seq 1 1000` ; do
b=`printf %04d%s ${a%}`
echo $b
mkdir $b
cd $b

cp ../blank/* .

 #set up the Fdata
                ln -s ../Fdata ./Fdata

# generate the lvs and bas
               PATH/TO/V2MakePrimBas.x $a

 cd ..

done












Comments