Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to pass vectors directly as second file #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ A Vesta file that contains vectors connecting the initial and final atomic posit
type: string
default: initial.vesta final.vesta

-cd --calculate_displacements
description: If 1, displacement between positions in Vesta files is calculated. Else, second file is assumed to contain vectors to render.
type: int
default: 1

-r --radius
description: vector radius (in angstrom)
type: float
Expand Down
18 changes: 12 additions & 6 deletions vesta_vectors.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import argparse
import re
from copy import deepcopy

def read_in(settings):

Expand All @@ -17,7 +18,7 @@ def read_in(settings):
data = open(filename,'r').read()
combined_data.append(data)

struct_match=re.search(r"STRUC.*THERI",data,flags=re.S)[0]
struct_match=re.search(r"STRUC.*THERI",data,flags=re.S).group(0)
pos_match=re.findall(r"\d+\D+\s+\D+\d+\s+\d+\.\d+\s+(.*?)\s+\d+\D+\s+\d+",struct_match)

if pos_match:
Expand Down Expand Up @@ -86,16 +87,16 @@ def print_to_file(data,settings):
VECTT_str += "{0} {1} {2} {3} {4} 0\n".format(i,settings.radius[0], settings.colour[0], settings.colour[1], settings.colour[2]) # set vector radius and colour
i+=1

ATOMT_match = re.search(r"ATOMT.*SCENE",data["initial_data"],flags=re.S)[0]
ATOMT_match = re.search(r"ATOMT.*SCENE",data["initial_data"],flags=re.S).group(0)
ATOMT_corrected = re.sub(r'([a-zA-Z]+\s+)\d+\.\d+',r"\1 0.0001",ATOMT_match) # this make all atoms reaaaalllly small

SITET_match = re.search(r"SITET.*VECTR",data["initial_data"],flags=re.S)[0]
SITET_match = re.search(r"SITET.*VECTR",data["initial_data"],flags=re.S).group(0)
SITET_corrected = re.sub(r'([a-zA-Z]+\d+\s+)\d+\.\d+',r"\1 0.0001",SITET_match) # this make all atoms reaaaalllly small

BONDP_match = re.search(r"BONDP.*POLYP",data["initial_data"],flags=re.S)[0]
BONDP_match = re.search(r"BONDP.*POLYP",data["initial_data"],flags=re.S).group(0)
BONDP_corrected = re.sub(r'(\d+\s+\d+\s+)\d+\.\d+',r"\1 0.0001",BONDP_match) # this makes all bonds reaaaalllly small

SBOND_match = re.search(r"SBOND.*SITET",data["initial_data"],flags=re.S)[0]
SBOND_match = re.search(r"SBOND.*SITET",data["initial_data"],flags=re.S).group(0)
SBOND_corrected = re.sub(r'(\s+\d\s+\d\s+\d\s+\d\s+\d\s+)\d+\.\d+',r"\1 0.0001",SBOND_match) # make all bonds reaaaalllly small

# substitute the above strings into the output data string
Expand All @@ -121,6 +122,8 @@ def parse_args():
parser.add_argument('--filenames','-f',type=str, nargs=2, required=False,
default=["initial.vesta","final.vesta"], help="name of initial and final vesta files"
)
parser.add_argument('--calculate_displacements','-cd',type=int, nargs='?', required=False,default=1, help="If 1, displacement between positions in Vesta files is calculated. Else, second file is assumed to contain vectors to render."
)
parser.add_argument('--colour','-c',type=int, nargs=3,required=False,
default=[255,0,0], help="vector colour (in RGB)")
parser.add_argument('--radius','-r',type=float, nargs=1, required=False,
Expand Down Expand Up @@ -151,7 +154,10 @@ def parse_args():
if settings.centre_atom:
data = calc_bounds(data)
data = delete_atoms(data)
data = calc_displacement(data)
if settings.calculate_displacements == 1:
data = calc_displacement(data)
else:
data["vectors"]=deepcopy(data["final_positions"])

print ("Printing to file")
print_to_file(data,settings)
Expand Down