Skip to content

Commit

Permalink
Code style standardization
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Mar 21, 2023
1 parent 0a6e391 commit 2b3c64c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ccinput/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
raise InvalidParameter(
f"Multiplicity must at least 1 (received '{multiplicity}')"
)

if parse_name:
if not file:
raise InvalidParameter(
Expand Down
16 changes: 9 additions & 7 deletions ccinput/packages/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_dihedral,
get_npxyz,
check_fragments,
add_fragments_xyz
add_fragments_xyz,
)
from ccinput.constants import CalcType, ATOMIC_NUMBER, LOWERCASE_ATOMIC_SYMBOLS
from ccinput.exceptions import InvalidParameter, ImpossibleCalculation
Expand Down Expand Up @@ -201,9 +201,11 @@ def handle_command(self):
self.command_line += f"{method}/{gen_keyword} "
else:
self.command_line += f"{method} "
#Counterpoise related commands processing
if 'counterpoise' in self.commands.keys() :
check_fragments(self.commands['counterpoise'][0],self.calc.fragments,self.calc.xyz)
# Counterpoise related commands processing
if "counterpoise" in self.commands.keys():
check_fragments(
self.commands["counterpoise"][0], self.calc.fragments, self.calc.xyz
)

def parse_custom_basis_set(self, base_bs):
custom_basis_sets = self.calc.parameters.custom_basis_sets
Expand Down Expand Up @@ -287,11 +289,11 @@ def parse_custom_basis_set(self, base_bs):

def handle_xyz(self):
lines = [i + "\n" for i in clean_xyz(self.calc.xyz).split("\n") if i != ""]
#If counterpoise correction is the option, modify xyz corresponding to fragments
if self.calc.fragments != None :
# If counterpoise correction is the option, modify xyz corresponding to fragments
if self.calc.fragments != None:
print(self.calc.fragments)
print(type(self.calc.fragments))
lines = add_fragments_xyz(lines,self.calc.fragments)
lines = add_fragments_xyz(lines, self.calc.fragments)
self.xyz_structure = "".join(lines)

def parse_custom_solvation_radii(self):
Expand Down
24 changes: 12 additions & 12 deletions ccinput/tests/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3793,13 +3793,13 @@ def test_sp_HF_CP_wrong_fragments(self):
"method": "HF",
"basis_set": "3-21G",
"charge": "0",
"specifications" : "counterpoise=2",
"fragments" : "1,1,1,1,2,2,2,2,2,5"
"specifications": "counterpoise=2",
"fragments": "1,1,1,1,2,2,2,2,2,5",
}

with self.assertRaises(InvalidParameter):
self.generate_calculation(**params)

def test_sp_HF_CP_1(self):
params = {
"nproc": 8,
Expand All @@ -3810,8 +3810,8 @@ def test_sp_HF_CP_1(self):
"method": "HF",
"basis_set": "3-21G",
"charge": "0",
"specifications" : "counterpoise=4 ",
"fragments" : "1,1,2,2,2,3,4,4,4"
"specifications": "counterpoise=4 ",
"fragments": "1,1,2,2,2,3,4,4,4",
}

inp = self.generate_calculation(**params)
Expand All @@ -3838,7 +3838,7 @@ def test_sp_HF_CP_1(self):
"""

self.assertTrue(self.is_equivalent(REF, inp.input_file))

def test_sp_HF_CP_2(self):
params = {
"nproc": 8,
Expand All @@ -3849,8 +3849,8 @@ def test_sp_HF_CP_2(self):
"method": "HF",
"basis_set": "3-21G",
"charge": "0",
"specifications" : "counterpoise=2",
"fragments" : "1,1,1,1,2,2,2,2,2"
"specifications": "counterpoise=2",
"fragments": "1,1,1,1,2,2,2,2,2",
}

inp = self.generate_calculation(**params)
Expand Down Expand Up @@ -3889,8 +3889,8 @@ def test_sp_HF_CP_wrong_num_frag(self):
"method": "HF",
"basis_set": "3-21G",
"charge": "0",
"specifications" : "counterpoise=3",
"fragments" : "1,2,3,3,3,4,5,5,5",
"specifications": "counterpoise=3",
"fragments": "1,2,3,3,3,4,5,5,5",
}

with self.assertRaises(InvalidParameter):
Expand All @@ -3906,8 +3906,8 @@ def test_sp_HF_CP_wrong_start_num(self):
"method": "HF",
"basis_set": "3-21G",
"charge": "0",
"specifications" : "counterpoise=3 ",
"fragments" : "2,2,2,2,2,3,3,3,4"
"specifications": "counterpoise=3 ",
"fragments": "2,2,2,2,2,3,3,3,4",
}

with self.assertRaises(InvalidParameter):
Expand Down
28 changes: 18 additions & 10 deletions ccinput/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,25 +421,33 @@ def get_charge_mult_from_name(name):
mult = 1

return charge, mult
def add_fragments_xyz(xyz,frag):


def add_fragments_xyz(xyz, frag):
"Add fragment information to xyz"
xyz_frag = []
frag = frag.split(',')
for i,line in enumerate(xyz):
frag = frag.split(",")
for i, line in enumerate(xyz):
line_splitted = line.split()
xyz_frag.append(f"{line_splitted[0]}(Fragment={frag[i]}) {line_splitted[1]} {line_splitted[2]} {line_splitted[3]} \n")
xyz_frag.append(
f"{line_splitted[0]}(Fragment={frag[i]}) {line_splitted[1]} {line_splitted[2]} {line_splitted[3]} \n"
)
return xyz_frag
def check_fragments(counterpoise,fragments,xyz):


def check_fragments(counterpoise, fragments, xyz):
"""Checks if the fragments are reasonably defined"""
fragments = fragments.split(',')
fragments = fragments.split(",")
try:
fragments = [int(i) for i in fragments]
except:
raise InvalidParameter("Fragment numbers must be integers")
unique_fragments = list(set(fragments))
if len([i + "\n" for i in clean_xyz(xyz).split("\n") if i != ""]) != len(fragments) :
if len([i + "\n" for i in clean_xyz(xyz).split("\n") if i != ""]) != len(fragments):
raise InvalidParameter("You must assign exactly one fragment to each atom")
elif (sorted(unique_fragments) != list(range(1,max(unique_fragments)+1))):
elif sorted(unique_fragments) != list(range(1, max(unique_fragments) + 1)):
raise InvalidParameter("Fragment numbers must start from 1")
elif ( len(unique_fragments) != int(counterpoise) ) :
raise InvalidParameter("Counterpoise keyword must be equal to the total number of fragments")
elif len(unique_fragments) != int(counterpoise):
raise InvalidParameter(
"Counterpoise keyword must be equal to the total number of fragments"
)
2 changes: 1 addition & 1 deletion ccinput/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def generate_calculation(
file=file,
driver=driver,
**kwargs,
fragments=fragments
fragments=fragments,
)

return process_calculation(calc)
Expand Down

0 comments on commit 2b3c64c

Please sign in to comment.